Jump to content

How to add a tween to a pool of sprites without it affecting their spawn positions over time?


Steph
 Share

Recommended Posts

I have created an endless runner where the player is collecting sweets as he runs. The sweets are taken from a pool of sprites and they spawn randomly between a maximum and minimum distance above each platform. All is working fine.

I would like to add a simple tween to the sweets so that they gently bob up and down instead of just being totally static. I have managed to produce this effect with the first line of code shown below. HOWEVER, as the game progresses and the sweets are recycled, the tween is making the sweets gradually spawn lower and lower on the screen which is not what I want. Please see my tween code below:

this.game.add.tween(this.sweetPool).to({y: this.sweetPool.y + 6}, 800, Phaser.Easing.Sinusoidal.InOut).yoyo(true).loop().start();

I have tried adding this.sweetPool.y -= 6 (see below) to try and stop the sprites moving lower over time but now it just seems to make them spawn higher and higher over time. 

this.sweetPool.y -= 6;
this.game.add.tween(this.sweetPool).to({y: this.sweetPool.y + 6}, 800, Phaser.Easing.Sinusoidal.InOut).yoyo(true).loop().start();

Can anyone suggest a simple way for me to achieve the affect I am after without it affecting the sprites position like this? Thanks in advance for any help.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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