Jump to content

Nothing works and black screen in Phaser 3


wasya1212
 Share

Recommended Posts

I create simple scene, but I can't see any images or text. All images are loaded. Update is not called. What's wrong?

export default class Play extends Phaser.Scene {
  constructor () {
    super('game');

    this.staticBg = null;
    this.scrollingBg = null;
    this.text = null;
  }

  preload() {
    this.load.image('static-bg', 'img/Simpsons_22_15_P1_640x360_279961667900.jpg');
  }

  create() {
    console.log("play"); // work
    this.add.image(0, 0, 'static-bg').setOrigin(0, 0).setScale(1.5, 1.7); // doesnt work
    this.text = this.add.text(10, 70);
    this.text.setText('Power: ' + 100);
  }

  update () {
    this.text.setText('Power: ' + 100);
  }
}

Game.js

import Game from "./js/game";
import { Preload, Play } from './js/states';

const config = {
  title: "Donuts",
  width: 1000,
  height: 800,
  parent: "game",
  // backgroundColor: "#18216D",
  pixelArt: true,
  scene: [
    // Preload,
    Play
  ],
  physics: {
    default: 'arcade',
    arcade: {
      debug: false,
      gravity: { y: 300 }
    }
  }
};

window.onload = () => {
  let game = new Game(config);
  game.start();
};

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...