Cocos2d加载多个动画和纹理时占用大量内存,如何解决

发布于 2025-01-03 17:05:23 字数 243 浏览 1 评论 0 原文

我正在开发一种游戏,在进入游戏场景之前需要加载 27 个纹理 altas(每个 1024 * 1024),

但有时我的游戏崩溃,因为收到内存警告

我知道 27 个纹理 altas 将使用: 4 * 27 * 1024 * 1024 = 108MB 内存 这是一个巨大的数量,但我确实需要在进入游戏之前加载它们。

有办法解决我的问题吗? 任何想法将不胜感激!

顺便提一句: 我使用的是cocos2d 1.0.1

I am working on a gameplay which needs load 27 texture altas (each one 1024 * 1024) before enter the game scene

but sometimes my game crash because receiving memory warning

I know 27 texture altas will use:
4 * 27 * 1024 * 1024 = 108mb memory
which is huge amount, but I really need to load them before entering game.

Is there anyway to solve my issue?
Any ideas will be very appreciated!

BTW:
I am using cocos2d 1.0.1

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

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

发布评论

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

评论(2

顾忌 2025-01-10 17:05:23

最好的建议是检查您的设计,以及预加载所有这些纹理的“需要”。我倾向于仅预加载最常用的纹理(动画和静态地图对象)。

例如,我有用于在 16 个字符类的地图上动画行走的纹理。我将“空闲”动画重新组合为 4 个纹理,并预加载它们,因为最初,当士兵进入场景时,它会空闲。移动动画位于单独的纹理中,对于移动中的每个角色类,这些纹理根据行进方向实时加载。当角色停止行走(空闲)时,我从缓存中删除未使用的纹理以及未使用的精灵帧。

另外:还有其他内存管理途径。您可以对某些纹理使用 16 位格式(默认为 RGB88888)。您可以通过转换为压缩的 PVR 格式来获得收益(这又是有损的,但对于某些纹理来说可能没问题)

看看 那里可以详细了解coco中的图片格式,以及与内存消耗的关系(以及加载、渲染速度)。但再次强调,在开始优化之前,请确保除了预加载所有方法之外没有其他选择。

Best suggestion is to review your design, and the 'need' for preloading all these textures. I tend to pre-load only the textures that are most frequently used (animations and static map objects).

For example, I have textures for animating walks on a map for 16 character classes. I regrouped the 'idle' animations in 4 textures, and preload these, because initially, when a soldier enters the scene, it idles. The moving animations are in separate textures that are loaded in real time, as a function of the direction of travel, for each character class in movement. When the characters stop walking (idle), i remove unused textures from the cache, as well as unused sprite frames.

Also: there are other avenues for memory management. You could use a 16 bit format for certain textures (RGB88888 is the default). You may gain by converting to compressed PVR format (once again this is lossy, but could be fine for some textures)

Look here and there to learn more about picture formats in coco, and the relationship to memory consumption (as well as load, rendering speeds). But once again, before you start optimizing, make certain you have no alternative to the pre-load all approach.

囍孤女 2025-01-10 17:05:23

使用 jpg 而不是 png 会使其不透明,您可以通过该图像的 alpha 图像使其透明,这将帮助您减小您现在使用的几乎一半的大小。

use jpg instead of png it will make that non transparent you can make that transparent by alpha image of that image it will help you reducing size almost half of you are using now.

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