W
W
Wasya UK2019-11-01 22:34:15
JavaScript
Wasya UK, 2019-11-01 22:34:15

Why does Phaser have a black screen?

It seems to work, there are no errors, and in the console I get that the scene is working. But there is no image or text. Also update does not work, what could be the problem?

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

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

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

  create() {
    console.log("play");
    this.staticBg = this.add.image(0, 0, 'background').setOrigin(0, 0).setScale(1.5, 1.7);
    this.text = this.add.text(10, 70);
    this.text.setText('Power: ' + 100);
  }

  update () {
    this.scrollingBg.tilePositionY -= 1;
    this.text.setText('Power: ' + 100);
  }
}

Main file:
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 }
    }
  }
};

let game;

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

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question