从一组字符串中创建ccsprites

时间:2013-03-21 05:20:20

标签: objective-c cocos2d-iphone nsarray

我已经创建了一个方法,将字符串对象与数组中枚举的每个成员匹配。我想为bArray的每个成员添加精灵,并将它们各自的字符串作为精灵图像进行匹配。我怎样才能做到这一点?

+ (NSArray *)names
{
    static NSMutableArray * _names = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _names = [NSMutableArray arrayWithCapacity:20];
        [_names insertObject:@"image1.png" atIndex:image1];
        [_names insertObject:@"image2.png" atIndex:image2];
        [_names insertObject:@"image3.png" atIndex:image3];
        [_names insertObject:@"image4.png" atIndex:image4];
        [_names insertObject:@"image5.png" atIndex:image5];
        [_names insertObject:@"image6.png" atIndex:image6];
                            .
                            .
                            .
                            .
    });

    return _names;
}

-(void)spriteGroups    {
    NSArray* sgArray;
    sgArray = [[spManager names] objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]];
    CCSprite* groupSprite = [CCSprite spriteWithFile:[sgArray[0]]];// this gives me an expected identifier error. I guess this is not the right way
    for (int i = 1; i > [sgArray count]; i++) {

    }
}

1 个答案:

答案 0 :(得分:0)

删除sgArray

周围的额外方括号
CCSprite* groupSprite = [CCSprite spriteWithFile:sgArray[0]];