2012-02-17 10 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)이 아닌 부울 값을 반환하지해야합니다. 코드를 변경하여 경고를 수정하는지 확인하십시오. 그렇지 않으면 문제가 코드에 있으며이 메서드가 호출되는 방식이 아닙니다.

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

+0

, 오류가 사라지지 않았다 , 내 손가락을 화면에 대면 내 이미지가 움직이지 않는다는 것을 인정합니다. 내 코딩에서 비린내가 보이니? 감사. – AaronChapmanDev

+0

절대적으로! ccTouchesMoved 있습니다. 와우, 나는 바보 같았다. 그것은 모두 잘 작동합니다. 잭에게 시간 낭비를해서 사과드립니다. 그래도 도와 ​​줘서 고마워. 나는 그것이 학습 경험이라고 생각한다. ;) – AaronChapmanDev

1

반환 형식은 (무효)가

-(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".