I’ve been trying to figure out how to get tweens to work in flashpunk and can’t find any good tutorials other than the api documentation.
Can someone explain how to work them for me? Thanks
I’ve been trying to figure out how to get tweens to work in flashpunk and can’t find any good tutorials other than the api documentation.
Can someone explain how to work them for me? Thanks
There is the base class Tween
nad then multiple utility tweens. Let’s start with the base class.
After you create a tween, you use start()
to start the time before calling the function. finish()
to end the function beforehand manually (calls the complete function). cancel()
to delete the tween from the container (doesn’t call the complete function).
The constructor has 4 parameters (all optional except the duration).
LOOPING
will be looping utill you stop or delete it. PERSIST
will loop once every time you call start()
. ONESHOT
will call once and then delete iteself from the container (if you want to use it again it must be added to another tweener).complete
atribute if you don’t want to stop the tween, cancel()
or 'finish()` (both of them explained above).Here an example of creation a Tween
and adding it to a Tweener
(in this case [and the most common one] a World
).
//somewhere inside a World function
var tween:Tween = new Tween (10, Tween.LOOPING, callback);
//Every 10 seconds 'callback' will be called, untill we finish() it or concel() it.
addTween(tween, true);
//this true starts the tween automatically, so we don't need another code line
But it doesn’t end here. The real thing with the tweens is that you can make subclasses with a better specific functionality. There already are a lot of usefull ones so i recomend to look the net.flashpunk.tweeners
subpackages (if you want to see how they work you can look the code).
I hope it helped you even if it was a bit. I’m not the best trying to explain things, so sorry if you can’t understan it well.