html {
height: 100%;
background-color: black;
}
body {
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
class GameScene extends Phaser.Scene {
create() {
this.add.rectangle(480, 360, 960, 720, 0xadd8e6);
this.enemy = this.physics.add.sprite(150, 360, "blah");
this.enemy.setVelocityX(-150);
}
update() {
// This condition ends up being called twice
if (this.enemy.body.center.x <= 0) {
console.log("Trigger", this.enemy.body.center.x);
this.enemy.body.reset(1, this.enemy.y);
console.log("Reset", this.enemy.body.center.x);
}
}
}
new Phaser.Game({
type: Phaser.AUTO,
width: 960,
height: 720,
// Add physics, arcade, scene, and audio
physics: {
default: "arcade",
arcade: {
gravity: {
y: 0
},
debug: true
}
},
scene: GameScene
});
This Pen doesn't use any external CSS resources.