時潛入 「學習了cocos2d遊戲開發與iOS5的」,在CH08古玩約CCSpriteBatchNode的addChild方法
在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;
}
所以批與質感 「怪物a.png」
在EnemyEntity.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個不同的框架中。因爲Only the CCSprites that are contained in that texture can be added to the CCSpriteBatchNode,'monster-b.png'不包含在'monster-a.png'中,爲什麼不同的敵人仍然可以加入批處理?
我的意思是:批量的紋理是'monster-a.png',但後來它的framename是'monster-b.png'的addchild,批量添加那個紋理中不包含的CCSprites? – limboy
沒有。紋理取自CCSpriteFrame。多個精靈幀可以引用相同的紋理 – Andrew
@Izyy:看看這裏:http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d。紋理是從多個圖像創建的,然後與CCSpriteFrameCache – Andrew