gpt4 book ai didi

ios - cocos2D 中未显示的 View 崩溃

转载 作者:行者123 更新时间:2023-11-28 23:05:36 24 4
gpt4 key购买 nike

没有错误或警告,但是当我尝试切换到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com