Pausable transitions/tween

Here's a library file which lets you perform regular transitions and pause/restart them. It also provides onStart, onComplete and onEnterFrame table and function listeners (onEnterFrame being called every time the transition/tween is updated.)

https://files.me.com/horacebury/ueitx5

I hope this is of use to some. It is the product of the work done here: http://developer.anscamobile.com/forum/2010/11/19/calling-easing-without-using-transitionto

Matt.

it would be good to be able to pass params to onComplete etc

with the normal transition methods it needs to be done by this method
http://developer.anscamobile.com/forum/2010/11/19/how-remove-object-after-using-transitionto-alpha0#comment-11566

As I understand it, the usual method of passing parameters is to create a table and give it a listener function, then pass the table as the onComplete listener table. Any parameters you need to have passed are stored within the table listener.

I know that there should really be an event table passed to the function/table listeners from my pausable transition, but it was very late and I was tired. I'll happily accept requests for improvements/extensions to the library, of course.

To kick off; would it be preferable to have a separate argument passed in the params table as the 'onCompleteParams' parameter? or something else?

Matt.

hi,

please could you give me an example of that method?

maybe we don't need onCompleteParams in that case (it'd also need onEnterFrameParams, on StartParams etc), so i'm keen to see how else it would be done

do you mean like this:

1
2
3
4
5
6
7
8
9
10
11
local rect = display.newRect(100,100,100,100)
rect:setFillColor(255,0,0)
 
local listener = {}
 
function listener:onComplete()
print(self.something)
end
 
listener.something="whatever"
transition.to(rect, {time=1000, x=200, onComplete=listener})

Hi @jmp909,

Yes, that is exactly what I mean. If you take a look towards the bottom of the main.lua in the app, you'll see that I've provided table and function listeners for all the events on both pausable transitions. If you were to add another value to one of the table listeners and print it within the table's function you'll get the functionality you're looking for.

It does feel a bit like going round the houses to get what, in other languages, would be a parameter in any situation, but in lua this is really a very straightforward solution and more powerful than it at first appears.

Let me know how you get on,

Matt.

but say you have two objects transitioning at the same time, both of which eventually call the same listener, how would you pass the same parameter for each but with different values?

in that case this is how i would have to do it currently

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
local rect = display.newRect(100,100,100,100)
rect:setFillColor(255,0,0)
 
local rect2 = display.newRect(100,100,100,100)
rect2:setFillColor(0,255,0)
 
local listeners = {}
 
function listeners:onComplete(obj)
print(listeners[obj].something)
end
 
listeners[rect]={something="whatever"}
listeners[rect2]={something="wherever"}
 
transition.to(rect, {time=1000, x=200, onComplete=listeners})
transition.to(rect2, {time=1000, y=200, onComplete=listeners})

@horacebury

Congratulations for your work on pausing transitions!

Thanks for sharing.

@jmp909 - Yes, you essentially have to use separate tables as the listeners. You'd have to do that anyway, as the unique parameters to the transitions would be separate tables, too.

@Magenda - Thanks. Let me know how you get on with it.

Matt.

this is great :D

Do you have any ideas how I can change the x param while the transition is running?

As with anything in lua, just set the value - the fact that a transition is running doesn't stop other values being modified.

M

yeah, but thats the problem .... i want to change the x value of the transition target :P

You want to change the target value of the transition? Then just cancel the transition and create a new one....

Just thinking about it further, if you're concerned about the change being obvious and not smooth enough, you can use an ease in the transition. Eg: http://developer.anscamobile.com/reference/index/easinginexpo

thx :)
I'll test it

@horacebury

I am having trouble figuring out how to implement your class into my app! Any way you could provide some source code? Thanks a lot!

Yep, as per the first post, look at the download and it should be one line of code. I intended it to simply replace the usual transition.to:

https://files.me.com/horacebury/ueitx5

To cancel a pausable tween would you do this?

pausabletween:Pause()
pausabletween = nil

Thank you,
Daniel

If I remember correctly, yes - but check the sample main.lua which comes with the download.

views:1534 update:2011/10/3 8:06:12
corona forums © 2003-2011