Jump to content

Black Screen, No Console-Errors


Jirash
 Share

Recommended Posts

Hi, I just set up Phaser on my Webserver and was trying the Hello World Example, however all I got was a black canvas and no error message.

 

Here's my simple code:

<!doctype html>
<html>
	<head>
		<title>phas3r</title>
		<script src="phaser.min.js"></script>
		<script src="game.js"></script>
	</head>
	<body>
	</body>
</html>
window.onload = function() {
	var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', {
		preload: preload,
		create: create
	});

	function preload() {
		game.load.image('logo', 'phaser.png');
	}

	function create() {
		var logo = game.add.sprite(game.world.centerX, game.world.centerY, 'logo');
		logo.anchor.setTo(0.5, 0.5);
		console.log(logo);
	}
};

The two JS are loaded correctly and the window.onload function is fired. However the preload and the create functions are not fired. 

 

The only message in Chrome's console is the "rainbowy" phaser-init message:

11:23:24.916 phaser.min.js:1      Phaser v3.1.0 (WebGL | Web Audio) https://phaser.io
 

Am I missing something?

I'm using IIS

Link to comment
Share on other sites

Additional informations:

  • Tried moving the preload and create functions out of the window.onload function
  • Tried placing the whole code inside the <body> tag like in the example
  • Can console.log the variable "game" and it seems to be a Phase.Game instance
Link to comment
Share on other sites

Hello @Jirash!

Could post the link to which Hello World Example you are following?

In Phaser 3.1 you should use a "config" JSON structure for initializing the Phaser.Game object, like so:

var config = {
  type: Phaser.AUTO,//renderer type
  width: 215,
  height: 270,
  scene: { // here you set up which functions you are using for each step in the game loop
    init: init,
    preload: preload,
    create: create
  }
};

//you finally instantiate the "game" object using the "config" one
var game = new Phaser.Game(config);

I've attached a example below with "Init", "Create" and "Preload" functions, to illustrate. Let me know if it helps you.

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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