我已经为我的NSMutable数组添加了精灵,现在我想找到它们;我正在使用这些方法:
- (void)selectSpriteForTouch:(CGPoint)touchLocation {
for (CCSprite *sprite in selectedSpritesArray) {
if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {
newSprite = sprite;
break;
}
}
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
[self selectSpriteForTouch:touchLocation];
return TRUE;
}
我该如何正确地做到这一点?现在我无法访问一些重叠的精灵。
谢谢!
答案 0 :(得分:1)
建议您是否要访问重叠的精灵:
- (NSMutableArray*)selectSpriteForTouch:(CGPoint)touchLocation {
NSMutableArray *sprites = [[NSMutableArray alloc] init];
for (CCSprite *sprite in selectedSpritesArray) {
if (CGRectContainsPoint(sprite.boundingBox, touchLocation)) {
[sprites addObject:sprite];
}
}
// dont forget to release this array when you are done with it
return sprites;
}