How to make initial phase of a tween not extreme?
-
Hi,
I tween a sprite like this:y = yTop; var dy = (yBottom - yTop); FlxTween.tween(this, { y: y + dy }, dy / speed, { type: FlxTween.PINGPONG, ease: FlxEase.sineInOut });
But it starts from top
y
position. I want it to start from any position I specify (inside the range, of course).
Is there a way?
-
Solved it by tweening the phase:
// member var phase: Float; // init dy = (yBottom - yTop); phase = Math.asin((y - yTop) / dy * 2 - 1); FlxTween.tween(this, { phase: phase + Math.PI * 2 }, dy * 2 / speed, { type: FlxTween.LOOPING });
and then calculating
y
manually with:// update y = ((Math.sin(phase) + 1) / 2 * dy) + yTop