带有大图像的Objective C iPad动画-使用什么方法?图像、方法、动画、iPad

2023-09-06 14:57:03 作者:乖戾

我正在尝试在 iPad 上构建一个天气应用程序,但我似乎需要一些动画方面的帮助.假设我正在为雷达制作动画,因此雷达源文件有 10 张 900x700 像素大小的 gif/jpeg 图片.我已经使用这里的教程尝试了 UIImage 动画技术:

I'm trying to build a weather application on the iPad but it seems that I need some help in animation. Say I'm animating a Radar, so the radar source files have 10 gif/jpeg pictures in 900x700 pixel size. I've tried the UIImage animation technique using the tutorial here:

http://www.icodeblog.com/2009/07/24/iphone-programming-tutorial-animating-a-game-sprite/

但似乎加载 10 张这么大的图像对于 iPad 来说太多了,并且由于内存警告而崩溃.我正在研究其他动画技术,但我似乎找不到能有效地做到这一点的方法.

but it seems that loading 10 images that big is too much for the iPad to handle and its crashing due to memory warnings. I'm researching other techniques to animate but I can't seem to find something that will do this efficiently.

我看过其他人,例如使用 sprites 的 Core Animation,以及使用 sprites 的 Cocos2D.有人能指出正确的方向来制作这些大图像的动画吗?(请记住,这些图像是动态的并且经常变化,因此必须在服务器上重新创建精灵并从 iPad 中获取来制作动画).谢谢

I've looked at others like Core Animation using sprites, and Cocos2D with sprites. Can someone point in the right direction the best way to animate these big images? (keep in mind that these images are dynamic and changes often so the sprites will have to be recreated on a server and fetched from the iPad to do the animation). Thanks

推荐答案

OpenGL 仅创建尺寸为 2 次方的纹理.对于您的图像,即 1024x1024,即每个图像的内存量.不过,这应该不是 iPad 的问题.

OpenGL only creates textures with dimensions at powers of 2. In the case of your images, that's 1024x1024, which is a meg of memory per image. Still, that shouldn't be a problem with the iPad.

首先,使用 Xcode 的分析工具进行调查,以确保图像不会在动画的每个循环中重复加载到内存中(可能是通过不共享缓存纹理的新对象).这可以从一开始就解决您的问题.

First, investigate using Xcode's profiling tools to ensure the images aren't being repeatedly loaded into memory at each loop of the animation (likely by way of new objects that aren't sharing cached textures). That could solve your problem from the start.

其次,我推荐使用 Cocos2D,如果只是为了轻松处理纹理和缓存.将图像放入 CCAnimation 中,将其弹出到 CCRepeatForever 中,使用 CCSequence 运行它.完成后点击 CCTextureCache 释放未使用的纹理.

Second, I recommend using Cocos2D if only for the easy handling of textures and caching. Toss the images into a CCAnimation, pop that into a CCRepeatForever, run it with a CCSequence. When you're done hit CCTextureCache to release unused textures.

第三,将您的动画帧速率降低到 30 或更低(如果仅针对此动画).它可能是 iPad,但你正在制作一个天气应用程序.不是电子游戏.

Third, lower your animation framerate to 30 or less (if only for this animation). It may be the iPad, but you making a weather app. Not a video game.

最后,降低图片的大小.证明你想要的一切,但大型雷达动画不会卖掉你的应用程序.并且仅仅因为一个网站可能已经很好地播放了该动画,请记住桌面比任何智能手机都具有更多的内存和功能.

Finally, downgrade the size of your image. Justify all you want, but a large radar animation will not sell your app. And just because a website might already be playing that animation beautifully, remember that a desktop has vastly more memory and power than any smart phone.