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.)
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?
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
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
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.
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
@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]
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]
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]