Jump to content

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


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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