2010-05-15 6 views
1

읽어 주셔서 감사합니다. 어떤 이유 Cocos2D TouchesEnded를 사용하면 스프라이트에 액세스 할 수 없습니까?

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch * touch = [touches anyObject]; 

    CGPoint location = [[CCDirector sharedDirector] convertToGL: [touch locationInView:touch.view]]; 
    CGRect myRect = CGRectMake(100, 120, 75, 113); 

    int tjx = sprite.position.x; 

    if(CGRectContainsPoint(myRect, location)) { 
     tjx ++;    
    } 
} 

, ccTouchesEnded는 내 "스프라이트"에 접근을 허용하지 않습니다. 또한 CGRectMake과 같이 사용하려고 :

CGRectMake(sprite.position.x, sprite.position.y, sprite.contentSize.Width, sprite.contentSize.Height) 

하지만 내 스프라이트의 위치 또는 높이를 액세스 할 수 없습니다. 나는 init 메소드에서 선언 될 때 "스프라이트"를 선언하지 않고 자식에게 추가한다.

도와주세요 !! 나는 여기서 정말로 간단한 것을 놓치고 있다고 확신한다.

답변

0

당신이 봤어,

  • [self sprite]
  • self.sprite
  • 스프라이트 속성으로 선언 된 경우 검사하고 당신이 그것을 합성했다?
+0

Ktag 메서드를 사용하여이 문제가 해결되었습니다. Rob 정말 고마워! – maiko

0

"sprite"는 아마도 init 메소드에서는 로컬로 선언되지만 클래스의 멤버는 선언되지 않습니다.

CCSprite* sprite = [self getChildByTag:123]; 

해당 태그에 의해 아이를 분리 할 때와 유사합니다 : 당신이 사용하여 해당 스프라이트에 액세스 할 수 있습니다에 나중에

sprite.tag = 123; // any arbitrary number to identify this sprite 

:

한 가지 해결책은 스프라이트에게 태그를 제공하는 것입니다 http://www.learn-cocos2d.com/knowledge-base/cocos2d-iphone-faq/learn-cocos2d-public-content/manual/cocos2d-general/14824-how-to-remove-a-child-from-the-nodescenelayer

+0

GH에 감사드립니다! 태그가 내 문제를 해결했습니다. – maiko

관련 문제