Game Development Reference
In-Depth Information
#import < Foundation/Foundation.h>
#import "cocos2d.h"
@interface EnemyCache : CCNode
CCSpriteBatchNode* batch;
NSMutableArray* enemies;
int updateCount;
After the spriteBatch , which contains all the enemy sprites, there's an enemies
NSMutableArray that stores a list of enemies of each type. The updateCount
variable is increased every frame and used to spawn enemies at regular intervals. The
init method of the EnemyCache is quite similar to the BulletCache init with
its initialization of the CCSpriteBatchNode :
-(id) init
if ((self = [super init]))
// get any image from the texture atlas we're using
CCSpriteFrame* frame = [[CCSpriteFrameCache sharedSpriteFrameCache]←
batch = [CCSpriteBatchNode batchNodeWithTexture:frame.texture];
[self addChild:batch];
[self initEnemies];
[self scheduleUpdate];
return self;
But because the code for initializing the enemies is a bit more complex, I extracted it
into its own method, as shown in Listing 8-11 .
Listing 8-11. Initializing the Pool of Enemies for Later Reuse
Search Nedrilad ::

Custom Search