ios - cocos2D 中未显示的 View 崩溃

标签 ios console cocos2d-iphone

没有错误或警告,但是当我尝试切换到 View 时崩溃了:

#import "Level1.h"
#import "LevelSelect.h"
#import "GameOver.h"



enum {

kTagPlayer, kTagComputer
};



@implementation Level1



+(id) scene {

CCScene *scene = [CCScene node];

Level1 *layer = [Level1 node];

[scene addChild: layer];

return scene;
}

-(id) init {
if( (self=[super init] )) {

CCSprite *player = [CCSprite spriteWithFile:@"Icon_Small_50.png"];
player.position = ccp(60, 60);
[self addChild:player z:2 tag:kTagPlayer];

CCSprite *computer = [CCSprite spriteWithFile:@"Icon_Small.png"];
computer.position = ccp(440, 160);
[self addChild:computer z:1 tag:kTagComputer];



[computer runAction:[CCMoveTo actionWithDuration:3.0
                                        position:ccp(player.position.x,   player.position.y)]];



self.isTouchEnabled = YES;



[self schedule:@selector(SpritesDidColide) 
      interval:.01];

}
return self;
}



-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:[myTouch view]];
point = [[CCDirector sharedDirector] convertToGL:point];

CCNode *player = [self getChildByTag:kTagPlayer];
[player setPosition:point];

CCNode *computer = [self getChildByTag:kTagComputer];
[computer runAction:[CCMoveTo actionWithDuration:3.0
                                    position:ccp(player.position.x, player.position.y)]];


}
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:[myTouch view]];
point = [[CCDirector sharedDirector] convertToGL:point];

CCNode *player = [self getChildByTag:kTagPlayer];
[player setPosition:point];

CCNode *computer = [self getChildByTag:kTagComputer];
[computer runAction:[CCMoveTo actionWithDuration:3.0
                                    position:ccp(player.position.x, player.position.y)]];

}



-(void) SpritesDidCollide {

CCNode *player = [self getChildByTag:kTagPlayer];
CCNode *computer = [self getChildByTag:kTagComputer];

float xDif = computer.position.x - player.position.x;
float yDif = computer.position.y - player.position.y;
float distance = sqrt(xDif * xDif + yDif * yDif);

if (distance < 45) {
[self unschedule:@selector(SpritesDidCollide)];
[[CCDirector sharedDirector] replaceScene:[CCTransitionScene transitionWithDuration:1        scene:[GameOver node]]];
}

}



@end

这是控制台中显示的内容:

* -[CCTimer initWithTarget:selector:interval:],/Users/GLaDOS/Documents/Xcode 4 Projects/2DPlatformer/2DPlatformer/libs/cocos2d/CCScheduler.m:110 断言失败 2012-02-17 19:13:07.460 2DPlatformer[709:707] 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“未找到选择器的签名 - 是否它有以下形式吗? -(无效)名称:(ccTime)dt' ** 首先抛出调用栈: (0x37f1d8bf 0x31a031e5 0x37f1d7b9 0x31e1c3b3 0x46565 0x4843f 0x3402d 0x948d3 0x32249 0x93a23 0x37f20814 0x37e7b7e1 0x2de31 0x2bdc9 0x37e77435 0x7087f 0x71019 0x727ff 0x352ef50f 0x352eef01 0x352d54ed 0x352d4d2d 0x379f2df3 0x37ef1553 0x37ef14f5 0x37ef0343 0x37e734dd 0x37e733a5 0x379f1fcd 0x35303743 0x912c7 0x2300) 终止调用抛出一个exceptionkill 当前语言:自动;当前 objective-c 辞职 程序以退出代码结束:0

最佳答案

我相信 schedule 方法会触发对表单选择器的回调:

-(void) SpritesDidCollide:(ccTime) dt{
    //  do your thing here. 
}

并将选择器更改为

[self schedule:@selector(SpritesDidCollide:) interval:.01];

关于ios - cocos2D 中未显示的 View 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9337459/

相关文章:

ios 应用内购买 : When and why does SKPaymentTransactionStateRestored get sent back as status of a transaction?

ios - 我想在 tableView 中显示来自 firebase 的数据

.net - Console.WriteLine 会阻塞吗?

python - 如何在 Python 中打印带下划线的内容?

python - 如何在后台运行python程序?

ios - Ccos2d 找不到 CCMoveTo

iphone - 通过 UITableViewCell 获取 tableView 的引用

ios - SBJson 和 Facebook iOS SDK 错误 "no visible @interface for ' NSData' 声明选择器 'JSONValue' ”

objective-c - 如何在 cocos2d 中暂停游戏?

opengl-es - 如何使用 Cocos2D 中的纹理绘制线条