Adding sprites to your game
A sprite is just a two-dimensional image used in the game. A sprite can represent a player character, an enemy, or even a background image. The following is a sample of a sprite:
A sprite can represent a tiny player character that is moved and animated, but at the same time, a sprite can be just a static image that we use to cover the whole background. The following is an example of this:
As you can see, sprites can come in different shapes and sizes depending on what they represent on the screen.
In Cocos2D, a sprite is represented by the CCSprite
class that we already used in the past when we displayed the earth image on the screen in the HelloWorld
project. The CCSprite
class has everything you need to load the sprite image from the disk, position it, and draw it on the screen.
Let's start by adding a background image to our game scene.