I have created a simple test game that randomly spawns icons that move around the screen. When you click on an icon, it disappears. I used sample code from SDK, and various internet sites.
I want to change the background, it is being set to BLACK. I would like to use a picture I have.
public void onDraw(Canvas canvas) {
canvas.drawColor(Color.BLACK);
...
}
The background color is set on the onDraw. If I try to draw a bitmap instead, the game will eventually crash from a memory problem. (it runs out of memory). I believe this is because the image is being drawn every time onDraw is called.
I have tried placing it in various locations, but maybe I'm just missing something. Any help would be great. Below is the code I am using to create the background. My ideal goal would be to only create the background once at the start. And be able to update it when called for.
Bitmap Background = BitmapFactory.decodeResource(getResources(),R.drawable.background);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int height = dm.heightPixels;
int width = dm.widthPixels;
Rect rec = new Rect(0, 0, width, height);
canvas.drawBitmap(Background, null, rec, null);