Game Development Reference
In-Depth Information
batch node in the BulletCache class. But the additional function call over-
head could possibly void any performance gain. If in doubt, always prefer to
make your code more readable and then refactor later to improve performance
where necessary, and only where necessary. And make no performance optim-
izations based on assumptions alone. Always measure performance before and
after making supposedly performance-enhancing changes!
Listing 8-4. The BulletCache Maintains a Pool of Bullets for Reuse
#import "Bullet.h"
@implementation BulletCache
-(id) init
if ((self = [super init]))
// get any bullet image from the texture atlas we're using
CCSpriteFrame* bulletFrame = [[CCSpriteFrameCache sharedSpriteFrameCache]←
// use the bullet's texture
batch = [CCSpriteBatchNode batchNodeWithTexture:bulletFrame.texture];
[self addChild:batch];
// Create a number of bullets up front and re-use them
for (int i = 0; i < 200; i++)
Bullet* bullet = [Bullet bullet];
bullet.visible = NO;
[batch addChild:bullet];
return self;
Search Nedrilad ::

Custom Search