Game Development Reference
In-Depth Information
Figure 6-2 . Drawing many CCSprite nodes using the same texture is more efficient when they're added to a CCS-
As a refresher, here's how to create a CCSprite the normal way:
CCSprite* sprite = [CCSprite spriteWithFile:@"bullet.png"];
[self addChild:sprite];
Listing 6-1 changes the creation of the same CCSprite to use a CCS-
priteBatchNode instead. Of course, just adding one CCSprite to it won't give
you any benefit, so I'll be adding a number of sprites using the same texture to the
CCSpriteBatchNode .
Listing 6-1. Creating Multiple CCSprites and Adding Them to a CCSpriteBatchNode to
Render Them Faster
CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithFile:@"bullet.png"];
[self addChild:batch];
for (int i = 0; i < 100; i++)
CCSprite* bullet = [CCSprite spriteWithFile:@"bullet.png"];
[batch addChild:bullet];
Search Nedrilad ::

Custom Search