added automatic scaling and implemented Menu Scene

Signed-off-by: Pascal Syma <pascal@syma.dev>
This commit is contained in:
2020-02-11 01:45:53 +01:00
parent 94ba56f2aa
commit 45b9891716
+14 -24
View File
@@ -1,32 +1,22 @@
import Phaser from "phaser"; import Phaser from "phaser";
import logoImg from "./assets/logo.png"; import Menu from "./scenes/Menu";
const ratio = 16 / 9; // any ratio you want, 16/9 landscape or 9/16 portrait
const DEFAULT_HEIGHT = 1080; // any height you want
const DEFAULT_WIDTH = ratio * DEFAULT_HEIGHT;
const config = { const config = {
type: Phaser.AUTO, type: Phaser.AUTO,
scale: {
mode: Phaser.Scale.FIT,
autoCenter: Phaser.Scale.CENTER_BOTH,
width: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT
},
parent: "phaser-example", parent: "phaser-example",
width: 800, scene: [Menu],
height: 600, // pixelArt: true,
scene: { // roundPixels: true
preload: preload,
create: create
}
}; };
const game = new Phaser.Game(config); const game = new Phaser.Game(config);
function preload() {
this.load.image("logo", logoImg);
}
function create() {
const logo = this.add.image(400, 150, "logo");
this.tweens.add({
targets: logo,
y: 450,
duration: 2000,
ease: "Power2",
yoyo: true,
loop: -1
});
}