2012-02-17 197 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".