Jump to content

I'm trying to learn phaser 3


peteblank
 Share

Recommended Posts

Hello I'm just starting out phaser 3.

I followed the tutorial but I can't get the sprite to load. 

I used the following. 

  function preload ()
    {
        this.load.image('dog', 'dog.png');
    }

    function create ()
    {
     this.add.image(200,200,'dog');
    }

The dog.png image is located on the same folder. 

What am I doing wrong?

Link to comment
Share on other sites

I'm just starting out in phaser 3 as well, its pretty confusing haha. I believe you need to make a variable for the dog.

The code should look like this:

function preload()

{

this.load.image('dog', 'assets/dog.png');

}

function create()

{

var dog = this.add.image('dog'); 

//You could also create "var dog" prior to this, and all you have to do here is: dog =  this.add.image('dog'); 

}

Link to comment
Share on other sites

Making a variable wouldn't do anything by itself. It would be useful only if you need to reference the image later.

It's likely that the problem here was not using a web server. Because of the security rules of browsers, you cannot load local files from within a web page, even one which is also a local file. You need to have a web server running locally so you can load files normally.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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