Transition with discrete callbacks (and transition loops)

Using the transition effects, it is easy to produce smooth movement, but some transitions are actually discrete.

For example, consider a sprite(sheet) with 20 images. To animate the sprite, you can use the built in play() methods, but this makes it difficult to integrate and activate custom logic. Such as when using a countdown timer with custom states, where you want to know exactly where in the animation you are.

Another example is the common "transition to something, then transition back" approach.

I would suggests that the transition.to(obj, params) accept two extra param values: { steps = 20, onStep = handler }

That way it would be easy to do something like:
local sprite = ...code to load spritesheet and sprite ...
sprite.step = function(self, event)
self.currentFrame = event.step
end
transition.to(sprite, { time=500, step = sprite.frames, onStep = sprite })

Similarly, you could abuse it to create a simple back-n-forth type handler:
local obj = ... some obj creation ...
obj.discrete = function(self, event)
if event.step == 1 then
transition.to(obj, params_for_left)
else
transition.to(obj, params_for_right)
end
end

And while you are at it: can you add the "loops" parameter to transition so it behaves like the animation?

Thanks!

views:1658 update:2012/2/6 12:03:31
corona forums © 2003-2011