摩托罗拉 xoom 上的 Cocos2d android 纹理问题
我正在使用 Cocos2d 框架在 android 中开发一个游戏,最新版本来自 github(Weikuan Zhou)。
在我的游戏中,我使用了大量的图像(总图像大小约为 11MB)。
问题: 当我玩游戏超过 3 次时,我看到的是黑框而不是图像。
哪些步骤会重现该问题? 1. 当我通过游戏的“再次玩”功能玩游戏超过 3 次时。
预期产出是多少?你看到了什么? - 图像应正确显示,而不是“BLACK BOX”
。
在我的 logcat 中,我看到堆内存约为 13Mb。
- 我已经通过下面的方法释放了纹理
CCTextureCache.sharedTextureCache().removeAllTextures();
我还尝试手动删除精灵。 removeChild()
方法。
但到目前为止还没有成功找到任何解决方案。
如果有人对此有解决方案,请告诉我。
I am developing a game in android with Cocos2d framework with latest build from github(Weikuan Zhou).
In my game, I used lots of images(total images size is around 11MB).
Problem:
I am getting the black box instead of images when I play my game more than 3 times.
What steps will reproduce the problem?
1. When I play my game more than 3 times via "Play Again" functionality of my game.
What is the expected output? What do you see instead?
- images should be displayed properly instead of "BLACK BOX"
.
and in my logcat, I see the Heap memory goes around 13Mb.
- I already release Texture via below method
CCTextureCache.sharedTextureCache().removeAllTextures();
I also tried to remove sprite manually ex. removeChild()
method.
But so far not succeeding to find any solution.
If any one have solution for this please let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的描述,您遇到了与我完全相同的问题,即 Android 版的 cocos2d 在处理大量单独加载的单个精灵时确实有问题。
解决此问题的最佳途径是从此处获取(除非您有 Mac)zwoptex 的免费 Flash 版本 http://zwopple.com/zwoptex/static/downloads/zwoptex-flashversion.zip
这将让您构建spritesheets,我建议将尽可能多的精灵关联到每张纸上,同时尝试将它们合理地分组。
这主要是因为 cocos 对 spritesheet 中的所有 sprite 进行一次渲染,而不是对普通 sprite 的每个 sprite 进行一次渲染,因此大大减少了处理时间,并减少了内存使用量。
然后,您可以使用以下代码加载精灵表(不能保证此代码会执行,因为我从结构化项目中获取片段,但它将引导您找到正确的解决方案)
From what you're describing, you're hitting exactly the same problem i did, which is that cocos2d for android is really buggy when dealing with lots of single sprites loaded individually.
The best route to take to resolve this problem is to get hold of (unless you've got a mac) the free flash version of zwoptex from here http://zwopple.com/zwoptex/static/downloads/zwoptex-flashversion.zip
this will let you build up spritesheets, i suggest relating as many sprites as you can onto each sheet, whilst trying to keep them sensibly grouped.
This is mainly down to cocos doing a single render for ALL sprites in a spritesheet, rather than one render per sprite for normal sprites, hence massively reduced processing time, and much less memory usage.
you can then load the spritesheet with code such as (can't guarantee this code will execute as i'm grabbing snippets from a structured project but it will lead you to the right solution)
当您在运行时加载资源时会出现此问题。所以最好在场景开始之前加载资源。可以按如下操作。
这是我正在遵循的程序。
谢谢。
This problem happens when you load resources at run time. So it is better to load resources before the scene starts.You can do as follows.
These is the procedure that I am following.
Thanks.