Creating sprites
Sprites are the most important things in games. They are images that are displayed on the screen. In this recipe, you will learn how to create a sprite and display it.
Getting ready
You can add the image that you made in the previous chapter into your project, by performing the following steps:
- Copy the image into the
Resource
folderMyGame/Resources/res
. - Open your project in Xcode.
- Go to Product | Clean from the Xcode menu.
You have to clean and build when you add new images into the resource
folder. If you did not clean after adding new images, then Xcode will not recognize them. Finally, after you add the run_01.png
to your project, your project will be seen looking like the following screenshot:
How to do it...
We begin with modifying the HelloWorld::init
method in the following code:
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size size = Director::getInstance()->getWinSize(); auto sprite = Sprite::create("res/run_01...