In the game development world, sprites are the 2D images in your game. Since this is the case, being able to add sprites is a very important skill to know. To begin, I will assume you have a scene already setup. If you don’t, feel free to check out this guide of mine to get you up to speed. We will also need an image loaded. If you’re new to loading images, you can check out this tutorial to learn that.

In the create method of your scene, you can add a sprite to your game with the following syntax:

this.add.sprite(<x>, <y>, <key>);

In the example above, the key is the image key you defined in the preload method. Feel free to write the following code and change the image key to the one you defined.

this.add.sprite(128, 128, "myimage");

If we run our game in the browser, we should see something like the following with the image of your choice.

Hopefully this guide has been useful for you. If it has, you may be interested in checking out the rest of this series. If you would like to receive news of our latest tutorials and courses, be sure to fill out the form. Sharing this guide on your social media platform would also be much appreciated. Stay tuned for more parts to this series.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news regarding tutorials and courses we publish!

Please check your inbox to confirm your subscription.

Share This