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


  • Recently Browsing   0 members

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