I am trying to learn phaser js but have been stuck on figuring out why my background images are not displaying to the scene. I have tried moving the image file to different locations and also tried doing function declarations instead of methods everything with the same result. Thank you in advance for any guidance you may be able to provide! Btw I am using parcel-bundler Code & screenshot
First is main.js
import Phaser, { Physics } from "phaser" import { TitleScene } from "./scenes" const GameConfig = { width: 800, height: 500, type: Phaser.AUTO, physics: { default: "arcade", arcade: { gravity: { y: 0, }, }, }, }; const game = new Phaser.Game(GameConfig); game.scene.add("title", TitleScene); game.scene.start("title");
This is my scenes.js files:
import Phaser, { Textures } from "phaser" export class TitleScene extends Phaser.Scene { preload() { this.load.image("sky", "sky.png"); } create() { this.add.image(400, 250, "sky"); const titleText = this.add.text(400, 250, "Hello World!"); titleText.setOrigin(0.5,0.5); //this.add.arc(400, 250, 128, 0, 360, false, 0xff0000); } }; export class GameScene extends Phaser.Scene { preload() { } create() { } }
没有评论:
发表评论