Decoding many different resources continuously in Android -


i working on game android. game real time strategy game uses tiles or cells , has actors (units, trees, rock, etc.) occupy cells.

in game, cells , actors objects have own draw method. fear of speed problems, decode resource in map class , feed decoded image object's draw method.

like this:

_watercell = bitmapfactory.decoderesource(context.getresources(), r.drawable.watertile); ... _row.get(cell).draw(_watercell, canvas, _paint, _x, _y); 

this fine now, considering have few cell types , 1 actor how go when have hundreds of images decode without having decode resource every time draw object? , if decode of resources in map class, cause out of memory errors?

i cannot whether decoding resources cause out of memory error since don't know size. however, decoding of resource itself, assuming there enough memory handle whatever being decoded should not cause out of memory exception. more likley result is, depending on how need decode resources, slow app down.

have considered using cache? if you're decoding resources use simple lrucache as demonstrated in android docs avoid repeating process. if decode resources needed, store them cache, , check cache fore presence before decoding again - can save lot of time.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -