CCSpriteBatchNode
To improve the tasks involved in drawing a texture on the screen, we can take advantage of the CCSpriteBatchNode
class, which wraps the multiple sprite renders in just one execution.
The only objects that can be added to CCSpriteBatchNode
are CCSprite
instances or any other class derived from CCSprite
. There is another restriction: every child in the batch must make use of the same texture, but we will see in the next section that this isn't in fact a weakness.
Let's learn how to use this class by adding several enemies to the scene, so let's add the image that will represent them:
Right-click on the Resources group and select Add Files to "HumanApocalypse"….
Look for the
human-ipad.png
andhuman-ipadhd.png
files in theResources
folder.Be sure that Copy items into destination group's folder (if needed) is selected and click on Add.
Define a constant value for the number of human enemies that will be loaded by adding the following line to GameScene.m
after the imports section...