iPhone 使用 UIImageView 进行大量动画的最佳实践

发布于 2024-10-09 04:01:42 字数 272 浏览 0 评论 0原文

只是请求一些关于在 iphone 上制作动画图像的建议。我正在构建一个由具有 5 个动画的角色组成的应用程序。

每个动画由大约 50 个图像组成,平均持续时间为 3 秒。

我打算为每个动画创建一个图像数组,将它们作为 UIImageView 的源,并根据需要切换它们。但你可以猜到,这种方法会杀死我 iPhone 的内存,从而杀死该应用程序。 (250 张图片@每张 130K!)

所以这让我想知道其他人是如何解决这个问题的?也许把动画改成电影?

感谢您的任何建议。

Just requesting a little advice animating images on the iphone. I'm building an app that consists of a character with 5 animations.

Each animation consists of roughly 50 images with an average duration of 3 seconds.

I was going to create an array of images for each animation, have these as the source for an UIImageView and switch these as needed. But as you can guess this approach kills my iphone's memory and thus the app. (250 images @ 130K each!)

So this got me wondering how other people get around this? Maybe change the animations to movies?

Thanks for any advice.

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

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

发布评论

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

评论(2

榕城若虚 2024-10-16 04:01:42

如果你可以的话,我会推荐电影路线。它会更干净,而且性能可能会更高。

但是,如果您由于某种原因无法使用图像,以下是连续加载 5000 张全帧图像的性能:

[UIImage imageWithData:...] // 44.8 seconds

[UIImage imageWithContentsOfFile:...] // 52.3 seconds

[[UIImage alloc] initWithContentsOfFile:…] // 351.8 seconds

[UIImage imageNamed:...] // hung due to caching

I'd recommend the movie route, if you can get away with it. It'll be cleaner and likely much more performant.

However, if you're stuck with images for some reason, here's performance from loading 5000 full-frame images in succession:

[UIImage imageWithData:...] // 44.8 seconds

[UIImage imageWithContentsOfFile:...] // 52.3 seconds

[[UIImage alloc] initWithContentsOfFile:…] // 351.8 seconds

[UIImage imageNamed:...] // hung due to caching
反差帅 2024-10-16 04:01:42

您是否尝试过使用代表帧的 UIImages 数组在 UIImageView 上设置animationImages 属性。我过去曾这样做过,效果很好,但我的动画中没有像你那么多的图像。

如果图像中的数据太多,您可能需要做一些更复杂的事情,例如精灵图集。该方法将一堆帧组合成一个图像,然后通过更改大图像的可视部分来为帧设置动画。这样,整个内容就会立即加载,并且动画只会更改用户看到的图像部分。 Cocos2D 有很多围绕精灵动画的功能。如果animationImages 不起作用,您可能想尝试一下。

- 麦克风

Have you tried setting the animationImages property on a UIImageView with an array of UIImages representing your frames. I have done that in the past and it worked pretty well, but I didn't have as many images as you in my animation.

If there is too much data in your images, you may have to do something more complex, like a sprite atlas. That method combines a bunch of your frames as one image and then animates the frames by changing the viewable portion of the big image. That way the whole thing loads at once and the animation just changes the part of the image that the user sees. Cocos2D has a bunch of functionality around sprite animation. If the animationImages thing doesn't work, you might want to try that.

--Mike

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