在 ch08 中潜入“用 ios5 学习 cocos2d 游戏开发”时
在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;
}
所以批次是纹理“monster-a.png”
inEnemyEntity.m
的initWithType
方法
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]))
{
//...
}
所以返回的对象可能在 3 个不同的帧中。由于只有包含在该纹理中的 CCSprites 才能添加到 CCSpriteBatchNode中,显然 'monster-b.png' 不包含在 'monster-a.png' 中,为什么仍然可以将不同的敌人添加到批处理中?