curios about CCSpriteBatchNode's addchild method
Posted
by
lzyy
on Stack Overflow
See other posts from Stack Overflow
or by lzyy
Published on 2012-06-19T14:57:27Z
Indexed on
2012/06/19
15:16 UTC
Read the original article
Hit count: 295
when diving into "learn cocos2d game development with ios5", in ch08
in EnemyCache.m
-(id) init
{
if ((self = [super init]))
{
// get any image from the Texture Atlas we're using
CCSpriteFrame* frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"monster-a.png"];
batch = [CCSpriteBatchNode batchNodeWithTexture:frame.texture];
[self addChild:batch];
[self initEnemies];
[self scheduleUpdate];
}
return self;
}
so batch is with texture "monster-a.png"
in EnemyEntity.m
's initWithType
method
switch (type)
{
case EnemyTypeUFO:
enemyFrameName = @"monster-a.png";
bulletFrameName = @"shot-a.png";
break;
case EnemyTypeCruiser:
enemyFrameName = @"monster-b.png";
bulletFrameName = @"shot-b.png";
shootFrequency = 1.0f;
initialHitPoints = 3;
break;
case EnemyTypeBoss:
enemyFrameName = @"monster-c.png";
bulletFrameName = @"shot-c.png";
shootFrequency = 2.0f;
initialHitPoints = 15;
break;
default:
[NSException exceptionWithName:@"EnemyEntity Exception" reason:@"unhandled enemy type" userInfo:nil];
}
if ((self = [super initWithSpriteFrameName:enemyFrameName]))
{
//...
}
so the returned object may be in 3 different frame. since Only the CCSprites that are contained in that texture can be added to the CCSpriteBatchNode, obviously, 'monster-b.png' is not contained in 'monster-a.png', why the different enemy can still be added to the batch?
© Stack Overflow or respective owner