impact-tween
impact-tween copied to clipboard
Returned reference to tweenTarget in onComplete
Useful for situations where runtime property evaluation is necessary without a clear reference to the original object performing the tween. With .chain() ref properties are evaluated at the time of instantiation, and no longer accurately describe the game-world.
For example,
var player = this.getEntitiesByType( EntityPlayer )[0];
var enemy = this.getEntitiesByType( EntityEnemy )[0];
var jumpTween = player.tween({ y: player.pos.y + 100}, .5 );
var landOnEnemyTween = player.tween({ y: enemy.pos.y }, .5 );
jumpTween.chain( landOnEnemyTween )
// After the first tween starts, the second, chained tween has a y-pos ref to an enemy that may have moved to a new location
jumpTween.start()
This pull request fixes this by allowing for something like
player.tween({ y: player.pos.y + 100 }, .5, {
onComplete: function( target ) {
// This will accurately return the enemy pos and tween the
// original target which may or may not have been lost (think, iterating
// over instances a for loop)
target.tween({ y: enemy.pos.y }, .5 )
}
);
Any chance of this getting pulled into the main branch? Or was there a better solution incorporated that I don't know about?