Jump to content

Sine wave + tween


Recommended Posts


I'm trying to use sinCosGenerator together with a tween to move the player only along the X axis of a sine wave.

The 'player' is moving like I want, but I've set it to start at the middle of the game width, however on start it gets moved instantly to the left and it stars drawing the sine wave from there. I can't figure out why it's moving immediately to the left and not starting the wave in the middle as set.

// generate sine waves
var sin;
var sinData = game.math.sinCosGenerator(game.height, game.width / 2, 1, 10);
sin = sinData.sin;

this.player = game.add.sprite(game.width / 2, 860, "player");
// move ship along sin horizontally
this.sinTween = game.add.tween(this.player).to({
     x: sin
}, speed, Phaser.Easing.Linear.None, true, 0, -1);


I'm new to Phaser so I'm probably missing something simple. What could be the issue?

Thank you in advance for the 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...