Loading assets

In this lesson, we learn how to load and display images and sound.

Loading images
To load an image, we use the game.load.image function.

The first argument is the name we want to give to our loaded object. The second argument is the full path to the file.

Once an image is loaded, you can create an instance of it to be displayed on screen by adding a sprite:

The first two arguments are the X and Y coordinates, and the third is the name we gave to our object when we loaded it.

When you're done with an object and want to destroy it, just do:

Loading sounds
In the same way we load images, we can also load audio, with the game.load.audio function.

And then we create an audio object

And then we play it

Challenges

 * Can you create 100 objects scattered randomly on screen?