How to simply tween to and from original position once

265 views
Skip to first unread message

Shaun Michael K. Stone

unread,
Nov 8, 2015, 9:42:56 AM11/8/15
to HaxeFlixel
I see we have type Ping pong as a type of tween. Problem is it loops over and over.

I just want to tween an object to a higher scale, and then return to 1 once:

FlxTween.tween(object.scale, {
x: 1.2,
y: 1.2
}, 0.2, {
ease: FlxEase.elasticInOut,
type: FlxTween.PINGPONG,
complete: function(tween:FlxTween):Void {
tween.cancel();
}
});

When I call cancel, it stops when it reaches a scale of 1.2 instead of when it has returned back to 1 like the ping pong type should do.

Thanks.

JohnD

unread,
Nov 8, 2015, 1:54:06 PM11/8/15
to HaxeFlixel
Try using the FlxTween.executions field, which tells you how many times the PingPong tween has looped.
I'm not sure if this is a release feature, as I am using the dev branch.

FlxTween.tween(object.scale, {
 x
: 1.2,
 y
: 1.2
}, 0.2, {
 ease
: FlxEase.elasticInOut,
 type
: FlxTween.PINGPONG,
 complete
: function(tween:FlxTween):Void {
    if(tween.executions==2) {
     tween
.cancel();
   
}
 
}
});

Shaun Michael K. Stone

unread,
Nov 8, 2015, 1:56:32 PM11/8/15
to HaxeFlixel
That is exactly what I need! Thankfully available on master. Cheers!

JohnD

unread,
Nov 8, 2015, 1:59:43 PM11/8/15
to HaxeFlixel
np.

:-)

MegaLeon

unread,
Nov 10, 2015, 7:09:57 AM11/10/15
to HaxeFlixel
If you're on the dev branch, you can use Tween chaining as well, is case you'd want to have different onComplete functions when the tweens goes back and forth:

FlxTween.tween(this, {y: y - 4}, 0.05, {onComplete: createItem}})
 
.wait(0.05)
 
.then(FlxTween.tween(this, {y: y + 4}, 0.05, {onComplete: empty}));

Shaun Michael K. Stone

unread,
Nov 10, 2015, 7:12:13 AM11/10/15
to HaxeFlixel
That is good to know, I am not on the dev branch, but will move over in my next project and take note of this. Thank you!
Reply all
Reply to author
Forward
0 new messages