How to draw lots of bitmaps on screen in an Android game without slow performance

前端 未结 6 1981
一个人的身影
一个人的身影 2020-12-28 20:32

I want to make a tile based game for android. At the moment I am drawing each tile as a separate bitmap. I have a big for loop that reads from a string and draws different

6条回答
  •  温柔的废话
    2020-12-28 20:44

    The problem is pretty obvious. You are just leaking a hell lot of memory. Take a look in the LogCat and you'll see what I mean. 1. NEVER allocate strings each frame. They are immutable so every operation with a strings equals memory leaking. Use instead a simple char[] object that you modify. 2. Stop creating bitmap objects over and over again. I suppose that the DecodeBitmap method internally allocates a bitmap object for each call. It's bad to do that every frame.

    As a rule of thumb -> leaking memory and it's buddy the GC are very expensive operations that be avoided when drawing.

提交回复
热议问题