在 iPhone 上使用大型精灵表
我正在尝试在我的应用程序中使用精灵表动画。 第一个带有小精灵表的 POC 工作正常,但当我将精灵表更改为更大的精灵表时,我收到“check_safe_call:无法恢复当前帧”警告,并且应用程序退出。
快速搜索发现这个问题意味着我的应用程序占用了太多内存或图像尺寸太大。
我的图像大小为 4.9 Mb,尺寸为 6720 * 10080(哎呀!!)。我读到 iPhone 允许最大 3 Mb 的图像,尺寸高达 1024 * 1024。此外,精灵表图像尺寸应该是 2 的幂。
所以请让我知道如何使用这么大的精灵表。
一种方法是将精灵表切割成许多较小的精灵表并一次使用它们。
请建议您是否知道任何其他/更好的方法来容纳更大的精灵表,以及我的精灵表的问题是否是大小(4.9 Mb)或尺寸(6720 * 10080)。
(仅供参考,我不想播放电影,所以使用 MP4 文件对我来说不是一个选择。我需要根据加速度计输入对精灵表进行动画处理,并且我已经能够在我的 POC 中使用较小的精灵表实现这一点。)
谢谢, 斯瓦普尼尔
I am trying to use sprite sheet animation in my application.
The first POC with a small sprite sheet worked fine but as i change the sprite sheet to a bigger one, i get "check_safe_call: could not restore current frame" warning and the application quits.
A quick search revealed that this problem meant my app is taking too much memory or the image is too huge in dimension.
My image is 4.9 Mb and dimensions are 6720 * 10080 (oops!!). i read that iphone allows maximum 3 Mb image with dimensions up to 1024 * 1024. Also that the sprite sheet image dimensions should be a power of two.
So please let me know how i can use a sprite sheet this big.
One approach could be to cut the sprite sheet into many smaller sprite sheets and use them one at a time.
Please suggest if you know any other/better approach to accommodate bigger sprite sheets and whether the problem with my sprite sheet is size (4.9 Mb) OR dimensions (6720 * 10080).
(Just FYI, i am not trying to play a movie so using MP4 file instead is not an option for me. i need to animate the sprite sheet based on accelerometer input and i have been able to achieve that in my POC with smaller sprite sheet.)
Thanks,
Swapnil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该按照您的描述将精灵表切割成多个纹理。 iPhone 的内存和图形芯片根本无法在内存中同时保存该大小的图像/纹理。通过分割精灵表,当您使用它们时,它将处理将适当的纹理加载/卸载到内存中的问题。
您还可以考虑优化图像格式。使用 PVRTC 格式可以节省大量内存,但它只适合某些类型的图像。请参阅 此 Apple 页面了解更多信息。
You should cut up the sprite sheet into multiple textures as you describe. The iPhone's memory and graphics chip simply can't hold an image/texture of that size in memory at once. By splitting up the sprite sheet it will deal with loading/unloading the appropriate textures into memory when you use them.
You might also consider optimizing the image format. Using the PVRTC format can save a huge amount of memory, but it is only well-suited to certain kinds of images. See this Apple page for more information.
绝对将其保持在 2 的幂以内。此外,将 spritesheet 中的精灵保留在 2 的幂容器中(例如,您有一个 17x31 精灵...将其放入 32x32 容器中)。你的精灵表的问题在于 4.9mb 和尺寸。我会考虑使用 adobe fireworks 或 pngcrusher 来大幅减小精灵表的大小。
迈克·韦勒(Mike Weller)关于分割精灵表的说法是正确的(你根本不能最大1024)。我认为最好的选择是将你对精灵表所做的事情重新组织成元素(尽管在不了解细节的情况下很难说)。只有移动的东西才应该有多个框架。通过调用 spritesheet 上的位置并将它们放入游戏中,将它们覆盖在背景上(来自同一个 spritesheet)。
definitely keep it within powers of 2. also, keep the sprites within the spritesheet in containers that are powers of 2 (say, you have a 17x31 sprite... put it in a 32x32 container). the problem with your sprite sheet is both the 4.9mb and the dimensions. i would consider using adobe fireworks or pngcrusher to bring the size of your sprite sheet down considerably.
mike weller's right about splitting the sprite sheet up (you simply cannot max 1024). i think the best bet would be to reorganize what you're doing with your sprite sheet into elements (though it's tough to say without knowing particulars). only things that move should have multiple frames. overlay those over a background (from the same spritesheet) by calling there location on the spritesheet and tossing them into play.