我正在尝试制作我的第一个 cocos2d,花栗鼠 ipad 应用程序
我在我的 .h 文件中设置了一个“球” Sprite ,如下所示:
// HelloWorld Layer
@interface
HelloWorld : CCLayer {
cpSpace *space;
CCSprite *ball;
}
我像这样移动它(触摸):
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
// Determine speed of the target
int minDuration = 2.0;
int maxDuration = 4.0;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;
// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration
position:ccp(location.x, location.y)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(spriteMoveFinished:)];
[ball runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
[ball retain];
}
}
当我使用调试器运行时,我得到了这个:
2011-06-29 20:44:04.121 ballgame[3499:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HelloWorld spriteMoveFinished:]: unrecognized selector sent to instance 0x605a3e0'
它似乎工作了几次,然后似乎崩溃了,所以可能是它的内存泄漏?任何建议或建议都会很有帮助,这就像我的第一个应用程序。
干杯!
最佳答案
您正在对不存在的 HelloWorld
对象调用方法 (spriteMoveFinished:
)。您是否制作了 spriteMoveFinished:
方法?
'Unrecognized selector sent' = 调用不存在的方法。
关于objective-c - iPad 应用程序因 NSInvalidArgumentException 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6529498/