非常感谢您的阅读!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方法中声明的时候,我一直不知道“精灵”,并将其添加到子节点中。
请帮忙!!我确定我在这里错过了一些非常简单的事情。
我使用了Ktag方法,并解决了这个问题。非常感谢你Rob! – maiko 2010-06-03 01:06:21