Does anyone know how to use tween linear motion?


(Sharon Shalom Iluz) #1

does anyone know how to do a yoyo animation where i can control the speed too with a long press

how can i make this a yoyo animation

        var duckTween:VarTween = new VarTween();
        duckTween.tween(_duck,"x", FP.screen.width - _duck.width, 2, Ease.sineIn);
        addTween(duckTween, true);

(Jacob Albano) #2

I’m not sure what you mean by “yoyo animation”. Is that a tween that repeats once after it finishes?


(Sharon Shalom Iluz) #3

yes like this

its going back and forth in a loop

http://www.republicofcode.com/tutorials/flash/as3tweenclass/

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent; 

var myTween = new Tween(my_mc, "x", Strong.easeInOut, 100,300, 1, true); 

myTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
function onFinish(e:TweenEvent):void {
myTween.yoyo();
}

(Sharon Shalom Iluz) #4

do know how i can get this done?


(Jacob Albano) #5

I don’t, sorry. You can do it manually by starting another tween in the onComplete callback.


(Jonathan Stoler) #6

I might be misunderstanding something, but why not just:

// non-locally scope this variable!
private var t:Tween;

// then, to start it...
t = new Tween();
addTween(t);
yo1();

private function yo1():void
{
    t.complete = yo2;
    t.tween(...);
}

private function yo2():void
{
    t.complete = yo1;
    t.tween(...);    
}

(the ... part of each yo function should be opposites of one another; I don’t know specifically what you are tweening so I didn’t put real code in there)

And, if you want to stop it:

t.complete = null;

(Sharon Shalom Iluz) #7

thanks it works but not with tween but with vartween.

im trying to get my character to loop in an idle mode by code like i can change the speed when clicked.

thanks a lot


(Jonathan Stoler) #8

In that case, depending on your needs, you might want to just use a looping Anim, then cancel it when you receive a click.

Otherwise, you can still use tweens and just cancel it with tween.cancel() on mouse click, then re-use the tween starting code to restart it when you want to replay the idle animation.


(Sharon Shalom Iluz) #9

Thanks I am just new to AS3 so its hard for me because the flashpunk doc doesnt have examples like the regular as3 live docs.

it would be nice to see how you can get it to work just like really simple examples


(Zachary Lewis) #10

Tween is the base class for all tweens, but it doesn’t have any actual functionality. It handles the updating and processing of the tween. All the child types in net.flashpunk.tweens extend Tween and affect different things.