From 45b98917166a99120cbb52af9d1f7a3563ba5d1c Mon Sep 17 00:00:00 2001 From: Pascal Syma Date: Tue, 11 Feb 2020 01:45:53 +0100 Subject: [PATCH] added automatic scaling and implemented Menu Scene Signed-off-by: Pascal Syma --- src/index.js | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/index.js b/src/index.js index 2bd2609..8425b3f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,32 +1,22 @@ 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 = { type: Phaser.AUTO, + scale: { + mode: Phaser.Scale.FIT, + autoCenter: Phaser.Scale.CENTER_BOTH, + width: DEFAULT_WIDTH, + height: DEFAULT_HEIGHT + }, parent: "phaser-example", - width: 800, - height: 600, - scene: { - preload: preload, - create: create - } + scene: [Menu], + // pixelArt: true, + // roundPixels: true }; 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 - }); -}