2012-02-17 144 views
0

当这些代码块执行时,我的应用程序崩溃。没有错误,只是警告。警告说:“在执行'ccTouchesBegan:withEvent'时出现冲突的返回类型:'void'VS'BOOL'(又名'signed char')”请帮忙。cocos2D触摸屏崩溃

-(BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
return YES; 
} 

-(BOOL) 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)] 
]; 

return YES; 
} 

回答

2

当你的警告,美国需要这些方法返回任何结果(void),而不是一个布尔值。尝试改变它,看看它是否修复了警告,否则问题在于你的代码,而不是如何调用这些方法。

+0

我也更改为无效,错误没有消失,当我将手指放在屏幕上时,我的图像没有移动。你在我的编码中看到任何可疑的东西吗?谢谢。 – AaronChapmanDev 2012-02-17 22:59:42

+0

永远不要想!我有ccTouchesMoved。哇,我觉得愚蠢。它一切正常。我很抱歉浪费你时间杰克。感谢您的帮助。我想这是一种学习体验。 ;) – AaronChapmanDev 2012-02-17 23:01:36

1

返回类型上

-(BOOL) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

应该是(无效)

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

} 
1

有没有什么回报。

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; 
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; 

你应该使用它来进行单点触摸;

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event; 

它也支持多点触摸:

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{ 
    NSArray *allTouches = [[event allTouches] allObjects]; 
    for (int i=0; i<[allTouches count];i++) { 
     if ([some conditions]) { 
      CGPoint position = [(UITouch*)[allTouches objectAtIndex:i] locationInView:[[CCDirector sharedDirector]openGLView]]; 
      position.y = [[CCDirector sharedDirector]winSize].height - position.y; 
      //deal with the position; 
      return TRUE; 
     } 
    } 
return FALSE; 

}

必须主动式触控交互第一:

[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; 
//if support multi touch you must set swallowsTouches "NO".