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. [import]uid: 8271 topic_id: 3813 reply_id: 303813[/import]

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
[import]uid: 6645 topic_id: 3813 reply_id: 11630[/import]

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. [import]uid: 8271 topic_id: 3813 reply_id: 11641[/import]

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:
[lua]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})[/lua]

i’m guessing that would be a problem when multiple objects are calling onComplete, whereas onCompleteParams would be related to the specific object transition.

of cource i can add paramers to rect

[lua]function myComplete(obj)
print(obj.something)
end

rect.something = “whatever”
transition.to(rect, {time=1000, x=200, onComplete=myComplete })[/lua]

but that might not always be what we’re trying to do

thanks
j [import]uid: 6645 topic_id: 3813 reply_id: 11642[/import]

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. [import]uid: 8271 topic_id: 3813 reply_id: 11644[/import]

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

[lua]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})[/lua] [import]uid: 6645 topic_id: 3813 reply_id: 11645[/import]

@horacebury

Congratulations for your work on pausing transitions!

Thanks for sharing. [import]uid: 7356 topic_id: 3813 reply_id: 11646[/import]

@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. [import]uid: 8271 topic_id: 3813 reply_id: 11647[/import]

this is great :smiley:

Do you have any ideas how I can change the x param while the transition is running? [import]uid: 10820 topic_id: 3813 reply_id: 18192[/import]

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

M [import]uid: 8271 topic_id: 3813 reply_id: 18221[/import]

yeah, but thats the problem … i want to change the x value of the transition target :stuck_out_tongue: [import]uid: 10820 topic_id: 3813 reply_id: 18451[/import]

You want to change the target value of the transition? Then just cancel the transition and create a new one… [import]uid: 8271 topic_id: 3813 reply_id: 18456[/import]

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 [import]uid: 8271 topic_id: 3813 reply_id: 18457[/import]

thx :slight_smile:
I’ll test it [import]uid: 10820 topic_id: 3813 reply_id: 18624[/import]

@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! [import]uid: 9968 topic_id: 3813 reply_id: 25227[/import]

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 [import]uid: 8271 topic_id: 3813 reply_id: 25251[/import]

To cancel a pausable tween would you do this?

pausabletween:Pause()
pausabletween = nil

Thank you,
Daniel [import]uid: 4413 topic_id: 3813 reply_id: 31998[/import]

If I remember correctly, yes - but check the sample main.lua which comes with the download. [import]uid: 8271 topic_id: 3813 reply_id: 32006[/import]