Hello! I need help figuring out how to get my sprite to move left and right as it falls because of the built-in gravity. I don’t know why but whenever I try to use the cursor function to move left and right I can’t get any input to the sprite.
<script type="text/javascript">
var config = {
type: Phaser.WEBGL,
width: 1300,
height: 600,
backgroundColor: '#000',
//parent: 'phaser-example',
physics: {
default: 'arcade',
arcade: {
gravity: { y: 300 },
debug: true
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('bg', 'assets/background.png');
this.load.image('star', 'assets/sprites/peonay.png');
}
function create ()
{
//camera and world bounds
this.cameras.main.setBounds(0, 0, 1000 , 1200 );
this.physics.world.setBounds(220, 0, 850 , 1200);
//adding the background
this.add.image(250, 0, 'bg').setOrigin(0);
player = this.physics.add.sprite(650, 0, 'star');
player.setCollideWorldBounds(true);
this.cameras.main.startFollow(player, true, 0.05, 0.05);
cursors = this.input.keyboard.createCursorKeys();
}
function update () {
if (cursors.left.isDown)
{
player.setVelocityX(-500);
}
else if (cursors.right.isDown)
{
player.setVelocityX(500);
}
}
</script>
</body>
</html>