Hello there,
I am very new to js and phaser so I came across an issue and I was hoping to find some help here.
I want to make my character jump by pressing space but I cannot seem to get it to work. I was following along a tutorial but it didn’t work out for me…
Here is my code
class Scene2 extends Phaser.Scene {
constructor() {
super("playGame");
}
create() {
this.background = this.add.image(0, 0, "background");
this.background.setOrigin(0, 0);
this.player = this.physics.add.sprite(0, 330, "bunny_run")
.setOrigin(0, 0)
.setScale(4)
.setCollideWorldBounds(true)
.setGravityY(5000);
this.player.play("bunny_run_anims");
this.jumpBunny();
}
jumpBunny() {
this.input.keyboard.on('key_SPACE', () => {
if (!this.player.body.onFloor()) { return; }
this.player.setVelocityY(-1600);
console.log("please"); //test
})
}
update() {
}
}