A sprite is a rectangle with a picture applied to it. You may be wondering, why not just use a picture? Of course, we do load a picture up, then we won't be able to move or rotate it. Therefore, we apply a picture or texture to a rectangle that is able to move and rotate, making it look as if the picture is doing so. Let's learn how to do this:
- Since we will be loading images into our game project, which is in the root directory of the project, let's create a folder called Assets.
- In this folder, create another folder called graphics, and then copy and paste the sky.png file into the graphics folder:
To create sprites, we use the Sprite class from SFML. The Sprite class takes in a texture. Then, the picture is loaded using the Texture class. While drawing, you need to call window.draw.(sprite) to draw the sprite. Let's take a look at how to...