Sign in to follow this  
peteblank

I'm trying to learn phaser 3

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?

Share this post


Link to post
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'); 

}

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.