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

前端 未结 6 1958
一个人的身影
一个人的身影 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:38

    It looks like you are creating a new instance of each bitmap image for every tile rendered. Maybe instead of doing that, you could create one instance for each tile type? ex:

    private Bitmap wallTile = BitmapFactory.decodeResource(getResources(), R.drawable.walla);
    private Bitmap floorTile = BitmapFactory.decodeResource(getResources(), R.drawable.floore);
    

    Then reuse the same tile instance each time the tile is drawn. If this doesn't work, you should put in some kind of performance measurement to see what part of the code is taking the longest time, and minimize the amount of times that code is run, or try to slim it down.

    Disclaimer: I am not an Android programmer

提交回复
热议问题