How do I access my player from another function?
In my create I have:
this.player = this.physics.add.sprite(width/2, height/2, 'player');
var isMoving = false;
this.input.on('pointerdown', movePlayer);
and in movePlayer:
function movePlayer(pointer)
{alert(this.isMoving);alert(this.player);
if(!isMoving)
{
isMoving = true;
if(pointer.downX > width/2)
this.player.setVelocityX(100);alert();
else if(pointer.downX < width/2)
this.player.setVelocityX(-100);
}
}
Both the alerts give me undefined and the player doesnt move. I know there’s something wrong with the way I’m accessing it but I don’t know what because in the update function
this.player.setVelocityX(100);
works fine.