Jump to content

Change x/y target in tween


AlgoGames
 Share

Recommended Posts

I am using RESIZE mode and have a few tweens which move from one point to another. The moment I resize the game, I need to recalculate the new x/y target for the sprites and update the tweens otherwise sprites keep moving to the previous target location which is incorrect for new size of the game. I looked into updateTweenData method but could not achieve what I want to do. I have tried to pause the tweens in resize method and directly change properties' x/y (tween.properties.x, tween.properties.y) but it does not change anything and tweens keep moving to previous target location after I resume. Changing x/y using something like updateTweenData ("x", newValue) also makes no difference.

Does anyone know if this is supported and is possible to achieve?

Link to comment
Share on other sites

Hi, there is a timeline property for a tween, if you inspect it you will find many properties that you can tweak to achieve what you want:

http://phaser.io/docs/2.4.4/Phaser.Tween.html#timeline

For your case, here is an example of how you can update the tween during play:

You could easily adapt it to your scale ratio. Note that you also have to recalculate your new duration,otherwise it will run sort of fast forward to the new position. Also the tweenCondition I provided is position changing, but you can specify what you want to achieve (alpha change, scale change etcc)...

Link to comment
Share on other sites

3 hours ago, samid737 said:

Hi, there is a timeline property for a tween, if you inspect it you will find many properties that you can tweak to achieve what you want:

http://phaser.io/docs/2.4.4/Phaser.Tween.html#timeline

For your case, here is an example of how you can update the tween during play:

You could easily adapt it to your scale ratio. Note that you also have to recalculate your new duration,otherwise it will run sort of fast forward to the new position. Also the tweenCondition I provided is position changing, but you can specify what you want to achieve (alpha change, scale change etcc)...

Perfect. Exactly what I was looking for. Thanks much. Let me try this now.

Link to comment
Share on other sites

  • 2 weeks later...

The method specified by samid737 works perfectly.

samme, I am not sure how to use your method. The last line tween.to() would need to specify new x,y coordinates which I think is not allowed once tween has started. Am I missing something here?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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