에서 볼 수있는, CCLayer 표준 터치 대리인으로 등록 할 수 있습니다. 대상 대리인으로 등록해야합니다. 이 경우 CCLayer는 터치를 주장 할 수 있고 다른 터치 할 수있는 요소는이를받을 수 없습니다. 당신은 당신의 ccTouchBegan:withEvent:
방법은 단지 '돈이
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
BOOL shouldClaimTouch = NO;
BOOL layerContainsPoint = // check if current layer contains UITouch position
if(layerContainsPoint)
{
shouldClaimTouch = YES;
}
// do anything you want
return shouldClaimTouch;
}
처럼해야
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
@optional
// touch updates:
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event;
이 사람과 당신의 대리자 메서드를 교체해야합니다이 후 CCLayer 방법
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority: self.priority swallowsTouches:YES];
}
를 재정 의하여 그것을 할 수 있습니다 터치의 UI 좌표를 GL로 변환하는 것을 잊지 마십시오. 이 메서드가 YES를 반환하면이 터치는 다른 레이어에서 수신되지 않습니다.
이 답변은 최신 Cocos2D에서 유효합니까? 편집 : 이것은 현재 (같은) 답변 것 같다 http://www.cocos2d-iphone.org/wiki/doku.php/tips:touchdelegates – Jonny
아직 공식 문서는 구식입니다. 프로토콜 이름이 오래 전에 변경되었습니다. – Jonny