2014-07-09 1 views
0

저는 게임의 레벨을 디자인하기 위해 SpriteBuilder를 사용하고 있습니다. 게임에서 나는 스 와이프 때 움직이는 블록 오브젝트를 가지고 있습니다. 그러나 레벨에 해당 오브젝트가 두 개 이상있을 경우 각 오브젝트는 마지막으로 추가 된 오브젝트 만 참조합니다. 그것들은 모두 고유 한 객체로 초기화되지만, 내가 스 와이프하면 움직이지 않습니다. 올바르게 작동하는 유일한 것은 레벨에 마지막으로 추가 된 것입니다.같은 클래스의 여러 객체가 객체 중 하나만을 참조합니다

스 와이프 제스처가 여기에 있습니다.

- (void)didLoadFromCCB { 
// Listen for swipe gestures to the right and left 
UISwipeGestureRecognizer * swipeRight= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight)]; 
swipeRight.direction = UISwipeGestureRecognizerDirectionRight; 
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeRight]; 

UISwipeGestureRecognizer * swipeLeft= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)]; 
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; 
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeLeft]; 
} 

다음은 잘못된 개체를 자체로 기록하는 스 와이프 방법 중 하나입니다. 나는 또한 정확한 객체를 로깅하는 touch started 메소드를 가지고있다. 대신 swipeRight 방법을 사용

- (void)swipeRight { 

// Only move the object if it is being touched while swiping 
CCLOG(@" Swipe right %@", self); 
if (self.touched) { 
    // Move the object off the screen to the right 
    float width = [self parent].contentSizeInPoints.width; 
    [self swipeOffScreen:ccp(self.position.x + width, self.position.y)]; 
} 
} 

답변

0

, 나는 코드를 가져다가 touchMoved에서 true로 self.touched touchEnded 방법과 세트로 이동했다. 문제는 UIKit 스 와이프 래퍼와 Cocos2D 터치 메서드의 차이점이라고 생각합니다.