Jump to content

Chaining tweens with to()


Hsaka
 Share

Recommended Posts

Hi, I'm having an issue with tweens which are chained via multiple to() calls and starting them manually.

p = game.add.sprite(0, 0, 'diamond');var t = game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None).to({ y: 300 }, 1000, Phaser.Easing.Linear.None);t.start();

In the above code, the sprite does not move to x = 700 but moves immediately to y = 300. If, however, I set the autostart parameter to true and don't call start(), it works as expected.

p = game.add.sprite(0, 0, 'diamond');var t = game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None).chain(game.add.tween(p).to({ y: 300 }, 1000, Phaser.Easing.Linear.None));        t.start();

The above also works as expected. Not sure if this is a known issue or has already been addressed.

Link to comment
Share on other sites

That is because when I made the change to allow tween to be chained with multiple .to calls I didn't know how the guys at photonstorm wanted it to be so I tried to make as few changes as possible. So basically currently call to .to return the tween it created, so when you assigned your variable it assigned it to the second tween in the chain and started it so it does nothing.

 

Now there's a couple of way to fix this. First there could be a lastChildren variable on the first tween of the chain, and the .to call could always return that same first tween in the chain. This would allow the variable to always be assigned to the first tween in the chain when declaring tween this way.

 

I'll prepare a pull request for this and submit it to the dev branch soon.

Link to comment
Share on other sites

  • 3 years later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...