我正在为I-pad touch做一个小游戏,作为游戏编程模块的一部分。我只是根据触摸的按钮处理菜单简单的场景变化。它似乎工作得很好,除了一个特定的场景机会。
尝试触摸导致我进入选项菜单的按钮时出现以下错误:
- [MainMenu goToOptions:]:发送到实例的无法识别的选择器 0xae2a1d0 * 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [MainMenu goToOptions:]: 无法识别的选择器发送到实例0xae2a1d0'
而且,这是我的代码中与崩溃相关的部分,以及导致场景更改的两个函数:
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
CCActionInterval *actionInterval = [CCActionInterval actionWithDuration:0.1];
if (CGRectContainsPoint([self.startButton boundingBox], location)) {
[self.startButton setTexture:[[CCTextureCache sharedTextureCache] addImage:@"BeginButton.png"]];
id actionCallFunc = [CCCallFunc actionWithTarget:self selector:@selector(goToInstructions:)];
[self.background runAction: [CCSequence actions: actionInterval, actionCallFunc, nil]];
}
else if (CGRectContainsPoint([self.optionsButton boundingBox], location)) {
[self.optionsButton setTexture:[[CCTextureCache sharedTextureCache] addImage:@"OptionsButton.png"]];
id actionCallFunc = [CCCallFunc actionWithTarget:self selector:@selector(goToOptions:)];
[self.background runAction: [CCSequence actions: actionInterval, actionCallFunc, nil]];
}
}
}
-(void) goToInstructions:(id) sender
{
[[CCDirector sharedDirector] replaceScene: [CCTransitionSlideInL transitionWithDuration:2 scene:[InstructionsMenu node]]];
}
-(void) goToOpctions:(id) sender
{
[[CCDirector sharedDirector] replaceScene: [CCTransitionFlipY transitionWithDuration:2 scene:[OptionsMenu node]]];
}
@end
知道崩溃的原因是什么以及如何解决它?
答案 0 :(得分:5)
方法名称中有拼写错误,请尝试:
-(void) goToOptions:(id) sender { // <--- TYPO here