cocos2d修改数组

时间:2012-01-30 12:42:31

标签: iphone cocos2d-iphone nsmutablearray

我已经为我的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;    
}

我该如何正确地做到这一点?现在我无法访问一些重叠的精灵。

谢谢!

1 个答案:

答案 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;
}