Steph Posted October 23, 2018 Share Posted October 23, 2018 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 More sharing options...
Steph Posted October 23, 2018 Author Share Posted October 23, 2018 Actually I have just solved this issue. The solution is to add the tween to the individual sprites and not the whole pool. Silly me. Link to comment Share on other sites More sharing options...
Recommended Posts