Hi Richard!
Suppose the following code:
function update() {
// game's world size = 800 x 600
// At the begining sprite is located at (400,300)
if ( player.position.x < -player.width ) {
player.position.x = game.width
}
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
if ( 0 == player.velocity.x ) {
player.velocity.x = -200;
player.animations.play('walk');
}
}
}
It simply moves the sprite to the left side, and when it reaches the border it will appear on the right side then. Unfortunatelly this won't happen until I change player.position.x by player.x:
function update() {
// game's world size = 800 x 600
// At the begining sprite is located at (400,300)
if ( player.x < -player.width ) {
player.x = game.width
}
...
}
So my question is, what is the correct attribute I should use? Sprite.{x, y} or Sprite.position.{x,y}?
Thanks!
You should use Sprite.x/y as it's the only value that includes in the camera and scrollFactor.
Thanks Richard!
Most helpful comment
You should use Sprite.x/y as it's the only value that includes in the camera and scrollFactor.