snapshot transition - how to obtain pointer to the snapshot object upon transition onComplete

I’ve looked through the G2 docs and can’t find a way to determine the snapshot object when a transition on the snapshot.path fires the onComplete event.  Do I have to resort to this sort of unsatisfying stuff:  ???

local function SnapDone(snap) &nbsp;&nbsp;&nbsp; local maxlimit = 90 &nbsp;&nbsp;&nbsp; local minlimit = 20 &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; local y3 = -minlimit &nbsp;&nbsp;&nbsp; local y4 = minlimit &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; if snap.y4 \< minlimit+1 then y4 = maxlimit; y3 = -maxlimit end &nbsp;&nbsp;&nbsp; transition.to( snap, { y3=y3, y4=y4, &nbsp;&nbsp;&nbsp; time=2500, delay=1, transition=easing.outExpo, onComplete = SnapDone} ) end local snapshot = display.newSnapshot(200,200) local circle = display.newCircle( 0, 0, 55 ) circle:setStrokeColor(0, 0, 0, 1) circle.strokeWidth = 3 circle:setFillColor(.5, .5, .5, .05) snapshot.group:insert(circle) snapshot.x = 512 snapshot.y = 200 local maxlimit = 90 snapshot.path.y3 = -maxlimit snapshot.path.y4 = maxlimit transition.to( snapshot.path, { y3=-maxlimit, y4=maxlimit, time=2500, delay=2000, transition=easing.outExpo, onComplete = SnapDone} )

I get a ‘userdata’ table in SnapDone when the onComplete fires…  how do I get back to the snapshot object?

I’m running the code you provided above and it works fine without throwing an error.

OK, I re-read your question and from what I can see it’s not possible to get at the underlying snapshot.

The reason being that transition.to will return the object passed to it and since ‘path’ is a userdata attribute of the snapshot that’s what will get sent to onComplete.

Hmmmm… really reduces the utility of snapshots for my purposes. My application of snapshot was to reduce an object containing 30 children into a single snapshot ‘image’, since I never need the children after the parent is created. And I have a hundred or more of these parents in transitions at the same time. I thought that the use case for snapshots was a good fit… actually a perfect fit. I suppose I can put the snapshot into a container to achieve what I want! (?) Thanks for your input, inqemar.

I think putting it into a group or container and then transitioning that will probably be your best bet.

Rob

Never tried it, but would the following syntax work?

[lua]

transition.to( snapshot, { path.y3=-maxlimit, path.y4=maxlimit, time=2500, delay=2000, transition=easing.outExpo, onComplete = SnapDone} )

[/lua]

I’d suppose it working depends on how the lua compiler interprets the transition params.

Thanks, Rob… I will try that out.  SNAPSHOT will still save a ton of children hanging around, with nothing to do!

And I tried your suggestion, mpappas… compiler chokes on it.  I tried a few variations… no go.  Thanks for the idea!

Hey Rob,

I tried out the container idea, where basically the container holds the snapshot and I tried to transition the container instead of the snapshot.  Of course, the container does not have the x1, x2, etc path ability, which is what I wanted to transition in the snapshot, so I am stuck again.

I am wondering if there is a way to get the handle of a transition when the onComplete event is fired for the transition(?)  If so, I could store some info in the transition object which would allow me to track which snapshot it is associated with?  Stupid idea?

I’m running the code you provided above and it works fine without throwing an error.

OK, I re-read your question and from what I can see it’s not possible to get at the underlying snapshot.

The reason being that transition.to will return the object passed to it and since ‘path’ is a userdata attribute of the snapshot that’s what will get sent to onComplete.

Hmmmm… really reduces the utility of snapshots for my purposes. My application of snapshot was to reduce an object containing 30 children into a single snapshot ‘image’, since I never need the children after the parent is created. And I have a hundred or more of these parents in transitions at the same time. I thought that the use case for snapshots was a good fit… actually a perfect fit. I suppose I can put the snapshot into a container to achieve what I want! (?) Thanks for your input, inqemar.

I think putting it into a group or container and then transitioning that will probably be your best bet.

Rob

Never tried it, but would the following syntax work?

[lua]

transition.to( snapshot, { path.y3=-maxlimit, path.y4=maxlimit, time=2500, delay=2000, transition=easing.outExpo, onComplete = SnapDone} )

[/lua]

I’d suppose it working depends on how the lua compiler interprets the transition params.

Thanks, Rob… I will try that out.  SNAPSHOT will still save a ton of children hanging around, with nothing to do!

And I tried your suggestion, mpappas… compiler chokes on it.  I tried a few variations… no go.  Thanks for the idea!

Hey Rob,

I tried out the container idea, where basically the container holds the snapshot and I tried to transition the container instead of the snapshot.  Of course, the container does not have the x1, x2, etc path ability, which is what I wanted to transition in the snapshot, so I am stuck again.

I am wondering if there is a way to get the handle of a transition when the onComplete event is fired for the transition(?)  If so, I could store some info in the transition object which would allow me to track which snapshot it is associated with?  Stupid idea?