在cocos2D中未显示的视图崩溃

时间:2012-02-18 00:51:49

标签: ios console cocos2d-iphone

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

#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'而终止应用程序,原因:'找不到选择器的签名 - 确实它有以下形式? - (void)name:(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) 终止叫做抛出异常杀手 当前语言:auto;目前客观的c 放弃 程序以退出代码结束:0

1 个答案:

答案 0 :(得分:2)

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

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

并将选择器更改为

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