Hi, someone can help me please ? I’m new in phaser. I try to make a space shooter. I’d like to bring the ships back to the top of the screen when they explode. i arrive to make the animations of the explostion but after that the ships don’t appear again in the screen.
class Scene2 extends Phaser.Scene {
constructor() {
super("playgame");
}
/* --------------- CREATE SECTION -------------------- */
create() {
/* Pour charger le fond d'écran */
this.background = this.add.tileSprite(0, 0, config.width, config.height, "background");
this.planet = this.add.tileSprite(0, 0, config.width, config.height, "planet");
this.stars = this.add.tileSprite(0, 0, config.width, config.height, "stars");
this.background.setOrigin(0, 0);
this.planet.setOrigin(0, 0);
this.stars.setOrigin(0, 0);
/* enemy */
this.ship1 = this.add.sprite(config.width / 2 - 100, config.height / 2, "ship");
this.ship2 = this.add.sprite(config.width / 2, config.height / 2, "ship2");
this.ship3 = this.add.sprite(config.width / 2 + 100, config.height / 2, "ship3");
this.anims.create({
key: "ship1_anim",
frames: this.anims.generateFrameNumbers("ship"),
frameRate: 20,
repeat: -1
});
this.anims.create({
key: "ship2_anim",
frames: this.anims.generateFrameNumbers("ship2"),
frameRate: 10,
repeat: -1
});
this.anims.create({
key: "ship3_anim",
frames: this.anims.generateFrameNumbers("ship3"),
frameRate: 20,
repeat: -1
});
this.anims.create({
key: "explode",
frames: this.anims.generateFrameNumbers("explosion"),
frameRate: 20,
repeat: 0,
hideOnComplete: true
});
this.ship1.play("ship1_anim");
this.ship2.play("ship2_anim");
this.ship3.play("ship3_anim");
this.ship1.setInteractive();
this.ship2.setInteractive();
this.ship3.setInteractive();
this.input.on('gameobjectdown', this.destroyShip, this);
this.ship1.setScale(0.10);
this.ship2.setScale(0.10);
this.ship3.setScale(0.10);
this.ship1.flipY = true;
this.ship2.flipY = true;
this.ship3.flipY = true;
this.add.text(20, 20, "Playing game", { font: "25px Arial", fill: "yellow" });
}
/* fin create section */
/* ------------------------- UPDATE SECTION -------------------------*/
update() {
this.moveShip(this.ship1, 1);
this.moveShip(this.ship2, 2);
this.moveShip(this.ship3, 3);
this.background.tilePositionY -= 0.5;
this.planet.tilePositionY -= 0.5;
this.stars.tilePositionY -= 0.5;
}
/* fin update section */
moveShip(ship, speed) {
ship.y += speed;
if (ship.y > config.height) {
this.resetShipPos(ship);
}
}
resetShipPos(ship) {
ship.y = 0;
var randomX = Phaser.Math.Between(0, config.width);
ship.x = randomX;
}
destroyShip(pointer, gameObject) {
gameObject.setTexture("explosion");
gameObject.play("explode");
this.resetShipPos(ship);
}
}
the console don’t show any errors, so i’m a little lost. someone can help me please ?