austin reed
austin reed

Reputation: 1

Not able to see image loaded with Phaser 3.24.1

I am just starting to use phaser and the first thing I tried doing is to explore 'hello world' with image project that comes as a demo with installation. I have index.html, phaser.png and phaser.min.js in the same location in a folder. I am running Node.js and started it using npm http-server. When I actually do that, all I see if a black square with size 800x600 and nothing else. The code is like his:

<html>
    <head>
        <meta charset="UTF-8" />
        <title>hello phaser!</title>
        <script src="phaser.min.js"></script>
    </head>
    <body>
    <script type="text/javascript">
    window.onload = function() {
        var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { 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);
        }
    };
    </script>
    </body>
</html>

What is missing here?

Upvotes: 0

Views: 193

Answers (1)

Molly J
Molly J

Reputation: 519

You're trying to mix the old style Phaser2 Game constructor while importing Phaser3 so you're callbacks don't work.

See the Phaser3 "Hello World" tutorial here for more working code: https://phaser.io/tutorials/getting-started-phaser3/part5

Upvotes: 1

Related Questions