【发布时间】:2011-01-31 05:39:17
【问题描述】:
在我的应用程序中,我需要类似粒子系统的东西,所以我做了以下操作:
当应用程序初始化时,我会加载一个 UIImage
laserImage = [UIImage imageNamed:@"laser.png"];
UIImage *laserImage 在我的控制器的接口中声明。现在每次我需要一个新粒子时,这段代码都会生成一个:
// add new Laserimage
UIImageView *newLaser = [[UIImageView alloc] initWithImage:laserImage];
[newLaser setTag:[model.lasers count]-9];
[newLaser setBounds:CGRectMake(0, 0, 17, 1)];
[newLaser setOpaque:YES];
[self.view addSubview:newLaser];
[newLaser release];
请注意,图像只有 17px * 1px 小,model.lasers 是一个内部数组,用于执行与图形输出分开的所有计算。所以在我的主绘图循环中,我将所有 UIImageView 的位置设置为我的 model.lasers 数组中的计算位置:
for (int i = 0; i < [model.lasers count]; i++) {
[[self.view viewWithTag:i+10] setCenter:[[model.lasers objectAtIndex:i] pos]];
}
我将标签增加了 10,因为默认值为 0,我不想使用默认标签移动所有视图。
所以动画在大约 10 到 20 张图片时看起来不错,但在使用大约 60 张图片时确实会变慢。所以我的问题是:有什么方法可以优化这个而不用在 OpenGL ES 中重新开始?
【问题讨论】:
标签: objective-c iphone uiimageview performance