1

Thanks so much for reading!

- (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 ++;            
    }
}

For some reason, ccTouchesEnded isn't allowing me to access my "sprite". I also tried to use CGRectMake like so :

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

But I couldn't access my sprites position or height. I keep getting "sprite" undeclared when it is declared in the init method, and added to the child.

Please help!! I'm sure i'm missing something really simple here.

4

2 回答 2

0

“精灵”可能在 init 方法中本地声明,但不是该类的成员。

一种解决方案是给精灵一个标签:

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

稍后您可以使用以下命令访问该精灵:

CCSprite* sprite = [self getChildByTag:123];

它类似于通过标签删除一个孩子:http: //www.learn-cocos2d.com/knowledge-base/cocos2d-iphone-faq/learn-cocos2d-public-content/manual/cocos2d-general/14824-how-从节点场景层中删除子节点

于 2010-05-23T16:13:33.607 回答
0

你有没有尝试过,

  • [self sprite]
  • self.sprite
  • 检查 sprite 是否被声明为属性并且你合成了它吗?
于 2010-05-18T13:46:45.597 回答