====== StartScene ======
Die Startscene zeigt etwas Text am Bildschirm an und wartet darauf, dass die/der Spieler/in die Leertaste drückt, siehe die Methode update:
/**
* method update is called from phaser before each frame is rendered
*/
update(time: number, delta: number){
if(this.spacebar.isDown){
this.scene.start("MainScene");
}
}
import { gameHeight, gameWidth } from "../Globals.js";
import { MainScene } from "../mainscene/MainScene.js";
/**
* Simple class to demonstrate a start screne
*/
export class StartScene extends Phaser.Scene {
spacebar: Phaser.Input.Keyboard.Key;
constructor(){
super({
key: "StartScene",
active: true
});
}
preload(){
}
create(){
let text1 = this.add.text(gameWidth/2, gameHeight*0.2, "Boulder Dash", {
fontFamily: "sans-serif",
fontSize: "72px",
color: "#aaa",
stroke: "#666",
strokeThickness: 5,
align: 'center'
});
/**
* Define point inside text-element that is moved to the above given coordinates gameWidth/2, gameHeight*0.2:
*/
text1.setOrigin(0.5, 0.5);
let text2 = this.add.text(gameWidth/2, gameHeight * 0.4, "Press Space to start!", {
fontFamily: "sans-serif",
fontSize: "36px",
color: "#3f3",
stroke: "#666",
strokeThickness: 2,
align: 'center'
});
text2.setOrigin(0.5, 0.5);
this.spacebar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
}
/**
* method update is called from phaser before each frame is rendered
*/
update(time: number, delta: number){
if(this.spacebar.isDown){
this.scene.start("MainScene");
}
}
}