我按照 raywnderlich 的示例项目冒险进入了我的第一个 cocos2d 应用程序。
在该应用程序中添加移动目标,如下所示
-(void)addMonster
{
__strong CCSprite * monster = [CCSprite spriteWithFile:@"monster.png"];
CGSize winSize=[CCDirector sharedDirector].winSize;
int minY=monster.contentSize.height/2;
int maxY=winSize.height-minY;
int rangY=maxY-minY;
int actualY=(arc4random()%rangY)+minY;
monster.position=ccp(winSize.width+monster.contentSize.width, actualY);
[self addChild:monster];
monster.tag=1;
int minDuration=2.0;
int maxDuration=4.0;
int actualDuration=(arc4random()%(maxDuration-minDuration))+minDuration;
CCMoveTo *actionMove=[CCMoveTo actionWithDuration:actualDuration
position:ccp(-monster.contentSize.width/2, actualY)];
CCCallBlock *actionDone=[CCCallBlock actionWithBlock:^(CCSprite *node){
[node removeFromParentAndCleanup:YES];// crashed at this point
[_monsters removeObject:node];
}];
[monster runAction:[CCSequence actions:actionMove,actionDone,nil]];
[_monsters addObject:monster];
}
我从我的 CCLayerColor 子类(场景)的 -init 方法中安排了上述方法,如下所示
-(id)init
{
// player adding code
[self schedule:@selector(gameLogic) interval:1.0];
}
-(void)gameLogic
{
[self addMonster];
}
即从ipad屏幕的左端移动到右端
我的问题是应用程序在访问节点对象时在 CCCallBlock 中崩溃
我没有下载源代码,而是计划从起点复制这些步骤,但仍然找不到它的发布位置。帮帮我同行
更新:-我已经在崩溃时发布了截图