0

Hello i have a big question and i don't find a way to solve my problem till now.

I work on simple game with objective-c and cocos2D.

I have 3 different objects (sprites with animation) and four fixed position on the screen.

Alternately with a interval i want to display the different objects on the positions.

I wanted to do it with a double for() to position the objects. And in the for for i want to create a multidimensional array with all the objects.

And then i want to create a Method where i have access to the time-interval and the frequency of the different objects.

Do you think i can solve my problem with this solution or do you know a better way…??

It would be great if anybody could help me.

Thanky you

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"myPlist.plist"];
myArray = [[CCArray alloc] init];


for (int i = 1; i <= 2; i++) {
    for (int j = 1; j <= 2; j++) {
            Figure *figure = [Figure spriteWithSpriteFrameName:@"a0001.png"];
            figure.position = ccp(j * figure.contentSize.width + 50, i * figure.contentSize.height + 50);
            [myArray addObject: figure];
            [self addChild:figure z:1];
     }
}
4

1 回答 1

0

我不知道您如何构建您的 plist,但我想您已经以这种方式重命名了图像:

a0001.png
a0002.png
a0003.png

为什么您不尝试制作更简单的 for 循环而不是“for inside a for”,以便在您的视图中仅放置 3 张图像并像这样管理您的文件:

for (int i = 1; i < 3; i++) {

    Figure *figure = [Figure spriteWithSpriteFrameName:[NSString stringWithFormat:@"a000%i.png", i]]
    figure.position = //add something that fit with your layout
    [myArray addObject: figure];
    [self addChild:figure z:1];

 }
于 2013-05-14T14:40:58.927 回答