Добавление потока спрайтов с помощью CCSpriteBatchNode в cocos2d?
Поэтому я создал класс с именем Berries, который расширяет CCSpriteBatchNode. Ягоды в основном похожи на монеты в моей игре, добавляя к значению оценки, если они "столкнулись". Вот код, который я имею в своем классе Ягоды для CCSpriteBatchNode:
- (id) init
{
if((self = [super init]))
{
CCSpriteBatchNode* berryBatch1 = [CCSpriteBatchNode batchNodeWithFile:@"One.png"];
[self addChild:berryBatch1];
CCSpriteBatchNode* berryBatch2 = [CCSpriteBatchNode batchNodeWithFile:@"Two.png"];
[self addChild:berryBatch2];
CCSpriteBatchNode* berryBatch3 = [CCSpriteBatchNode batchNodeWithFile:@"Three.png"];
[self addChild:berryBatch3];
for (int i = 0; i < 100; i++)
{
CCSprite* berry1 = [CCSprite spriteWithFile: @"One.png"];
[berryBatch1 addChild:berry1];
CCSprite* berry2 = [CCSprite spriteWithFile: @"Two.png"];
[berryBatch2 addChild:berry2];
CCSprite* berry3 = [CCSprite spriteWithFile: @"Three.png"];
[berryBatch3 addChild:berry3];
}
numBerries =
}
return self;
}
numBerries - это int, который я сделал. Я пытаюсь выяснить количество ягод во всех трех CCSpriteBatchNodes, чтобы, когда я делаю метод detectCollision, я мог использовать его в цикле for.
Есть идеи?
1 ответ
Решение
Это просто:
numBerries = berryBatch1.children.count +
berryBatch2.children.count +
berryBatch3.children.count;