How to use lots of bitmaps in a game without exceeding VM memory budget?

南笙酒味 提交于 2020-01-17 02:51:26

问题


In my game i have 12 different animations and each animation consist of 10 bitmaps and each bitmap is 200x150 pixel. Every time user touches to the screen(virtual gamepad) one of the animations will play. Normally this is an easy job but performance wise i am having trouble. Loading all bitmaps on an array from the beginning of the game cause to crash game because of VM memory budget problem. It seems my other option is to recreate bitmaps everytime i need and then recyle them, but this might cause lag because of creating time and garbage collection. I can't think of third option so i am asking you. Is there any memory efficient and not laggy option ?


回答1:


That's 14MB of memory for your animations which might be a lot for the VM heap it should fit nicely into the graphics card memory. I am assuming that you are using OpenGL (if not you will almost have to). In which case you can build your frames one-by-one, bind them to a texture and release them from the VM's memtory. This will be fairly fast but I wouldn't do it often or offer some sort of loading feature if the lag is greater than 1/2 second or so.




回答2:


I would consider using a SpriteSheet for this. SpriteSheet would contain all the frames of the animation on one bitmap, and you can then programatically load the correct frame coordinates to create your animation.



来源:https://stackoverflow.com/questions/5136385/how-to-use-lots-of-bitmaps-in-a-game-without-exceeding-vm-memory-budget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!