Jirash Posted February 19, 2018 Share Posted February 19, 2018 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 More sharing options...
Jirash Posted February 19, 2018 Author Share Posted February 19, 2018 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 More sharing options...
DanielKlava Posted February 19, 2018 Share Posted February 19, 2018 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 More sharing options...
Jirash Posted February 19, 2018 Author Share Posted February 19, 2018 Hi Daniel Many thanks, the Config Approach fixed it for me! I was using the example https://phaser.io/tutorials/getting-started/part6, seems to be incompatible with 3.1.0 Link to comment Share on other sites More sharing options...
Recommended Posts