How to efficiently show many Images? (iPhone programming)

后端 未结 4 1274
感动是毒
感动是毒 2020-12-16 03:18

In my application I needed something like a particle system so I did the following:

While the application initializes I load a UIImage

laserImage = [         


        
4条回答
  •  隐瞒了意图╮
    2020-12-16 03:44

    As jeff7 and FenderMostro said, you're using the high-level API (UIKit), and you'd have better performance using the lower APIs, either CoreAnimation or OpenGL. (cocos2d is built on top of OpenGL)

    • Your best option would be to use CALayers instead of UIImageViews, get a CGImageRef from your UIImage and set it as the contents for these layers.

    • Also, you might want to keep a pool of CALayers and reuse them by hiding/showing as necessary. 60 CALayers of 17*1 pixels is not much, I've been doing it with hundreds of them without needing extra optimization.

    This way, the images will already be decompressed and available in video memory. When using UIKit, everything goes through the CPU, not to mention the creation of UIViews which are pretty heavy objects.

提交回复
热议问题