Question

During my game loop I am constantly loading images using

BitmapFactory.decodeResource(getResources(), R.drawable.objectx);

Most of the time I'm calling images that have already been decoded earlier. Am I slowing down execution by decoding the resource every time?
Is it better to store every image into a Map (or Dictionary) at the beginning of the program? If so, how do you get the resource IDs for all images in the drawable folder?

Was it helpful?

Solution

Is it better to store every image into a Map (or Dictionary) at the beginning of the program?

Yeah... it's much better. Or you can store them as soon as you need them; is not necessary to store them all at the beginning.

If so, how do you get the resource IDs for all images in the drawable folder?

The drawable folder does not contains images only; it also have xml resources. So that's not the way to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top