0
我使用RAYWENDERLICH的一些代碼,這是一個很棒的網站,但那不是重點。我下車即是給了我一個很難該網站的代碼是這樣的(IM增加怪物/鬼魂是應該在屏幕上移動):由於CCBlock引發異常?
- (void) addMonster {
CCSprite * monster = [CCSprite spriteWithImageNamed:@"Ghost.png"];
// Determine where to spawn the monster along the Y axis
CGSize viewSize = [CCDirector sharedDirector].viewSize;
int minY = monster.contentSize.height/2;
int maxY = viewSize.height - monster.contentSize.height/2;
int rangeY = maxY - minY;
int actualY = (arc4random() % rangeY) + minY;
// Create the monster slightly off-screen along the right edge,
// and along a random position along the Y axis as calculated above
monster.position = ccp(viewSize.width + monster.contentSize.width/2, actualY);
[self addChild:monster z: -4];
// Determine speed of the monster
int minDuration = 2.0;
int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
// Create the actions
CCActionMoveTo * actionMove = [CCActionMoveTo actionWithDuration:actualDuration
position:ccp(-monster.contentSize.width/2, actualY)];
CCActionCallBlock * actionMoveDone = [CCActionCallBlock actionWithBlock:^(CCNode *node) {
[node removeFromParentAndCleanup:YES];
}];
[monster runAction:[CCActionSequence actions:actionMove, actionMoveDone, nil]];
}
上面的代碼上面的init方法添加,雖然這是init方法裏面添加:
//How often a new ghost gets produced
[self schedule:@selector(gameLogic:) interval:1.0];
而且init方法後,我有回調方法如下:
//The call back function
-(void)gameLogic:(CCTime)dt {
[self addMonster];
}
但是,我得到了我一個拋出的異常夫婦o f秒運行應用程序導致終止。在調試器中的消息內容如下:
-[__NSGlobalBlock__ removeFromParentAndCleanup:]: unrecognized selector sent to instance 0x10ef5ee20
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSGlobalBlock__ removeFromParentAndCleanup:]: unrecognized selector sent to instance 0x10ef5ee20'
所以就我的理解去有什麼不對與塊的方法,但我不能縫正是搞清楚。
有什麼線索可以解決這個問題和/或代碼有什麼問題,爲什麼?