更有效地旋转 64 个 CCSprite?

发布于 2024-09-15 05:13:00 字数 950 浏览 3 评论 0原文

我有一个 8 x 8 的精灵矩阵,我需要能够将它们同时旋转 90 度。我完成的方法是使用嵌套的 for 循环和精灵指针的二维数组。

for(row = 0;row<9;row++){
    for(column = 0;column<8;column++){
         [trolls[row][column] runAction:[RotateBy actionWithDuration:0.01 angle:90]]; 
    }
}

有没有更有效的方法来做到这一点?在它们全部旋转之前似乎有一个滞后。

编辑:这是我回应炼金术士的更多代码:

@interface GameLayer : CCLayer {
    CCSprite *monsters[8][8];
    //other code ...
}
@property @property (nonatomic,retain) *monsters
//other code ...
@end

@implementation
@synthesize monsters

-(void)init {
    NSString *filename;
    int row,column,randnum;
    for(row = 0;row<9;row++){
        for(column = 0;column<8;column++){
            randnNum =(int)Rand(8);
            filename =stringWithFormat:@"%d.png",randnNum];
            monsters[row][column] = [[[CCSprite alloc] initWithImage:(CGImageRef)filename key:filename] autorelease];
        }
    }
 //other code ...
}

I have an 8 by 8 matrix of sprites that I need to be able to rotate all of them 90 degrees at once. The way I've done it is using nested for loops, and a 2 dimensional array of sprite pointers.

for(row = 0;row<9;row++){
    for(column = 0;column<8;column++){
         [trolls[row][column] runAction:[RotateBy actionWithDuration:0.01 angle:90]]; 
    }
}

Is there a more efficient way of doing this? There seems to be a lag before they all rotate.

EDIT: here's is more of my code to respond to the alchemist:

@interface GameLayer : CCLayer {
    CCSprite *monsters[8][8];
    //other code ...
}
@property @property (nonatomic,retain) *monsters
//other code ...
@end

@implementation
@synthesize monsters

-(void)init {
    NSString *filename;
    int row,column,randnum;
    for(row = 0;row<9;row++){
        for(column = 0;column<8;column++){
            randnNum =(int)Rand(8);
            filename =stringWithFormat:@"%d.png",randnNum];
            monsters[row][column] = [[[CCSprite alloc] initWithImage:(CGImageRef)filename key:filename] autorelease];
        }
    }
 //other code ...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦归所梦 2024-09-22 05:13:00

从你的动作持续时间来看,你似乎希望它们立即旋转,或者非常接近。

如果您简单地手动设置旋转,似乎会更快一点:

for(row = 0;row<9;row++){
    for(column = 0;column<8;column++){
         trolls[row][column].rotation += 90; 
    }
}

仍然有旋转每个精灵的计算,但在动画期间不可能多次执行。

如果您只打算以 90 度增量执行此操作,则另一个考虑因素是在 4 次旋转中的每一次旋转中都有精灵,并制作帧动画。然后只需选择适当动画的帧即可。

It looks like from the duration of your action that you want them to rotate instantly, or pretty close.

It seems like it would be a bit faster if you simply set the rotation manually:

for(row = 0;row<9;row++){
    for(column = 0;column<8;column++){
         trolls[row][column].rotation += 90; 
    }
}

There is still the computation of rotating each sprite, but no chance that it would have to do it more than once during the animation.

Another consideration if you are only ever going to be doing this in 90 degree increments would be to have sprites at each of the 4 rotations, and make a frame animation. Then just choose the frame of the appropriate animation.

瀟灑尐姊 2024-09-22 05:13:00

我唯一能想到的就是逐个精灵地旋转精灵,以便该过程可以识别并利用预取。更多代码会有所帮助。

The only thing I can thing of at the top of my head is to do the rotation sprite-by-sprite so the process can take recognize and take advantage of prefetching. More code would be helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文