I have the following code;
@Override
public void run()
{
tickCount = 0L;
Log.d(TAG, "Starting game loop");
while (running)
{
try
{
gameCanvas = surfaceHolder.lockCanvas();
synchronized (surfaceHolder)
{
// Log.d(TAG, tickCount + " ticks so far");
tickCount++;
updateGameState();
render(gameCanvas);
}
} finally
{
if (gameCanvas != null)
{
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
surfaceHolder.unlockCanvasAndPost(gameCanvas);
}
}
}
}
The problem I am having is when I test the application the bitmap doesnt display. I have tried copying a drawable using and using setBitmap.
eg.
mutableBackground = backgroundImage.copy(Bitmap.Config.ARGB_8888, true);
where backgroundImage is a decoded drawable resource.
and..
mutableBackground = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
gameCanvas = new Canvas();
gameCanvas.setBitmap(mutableBackground);
gameCanvas.drawColor(Color.GREEN);
and..
gameCanvas = new Canvas(mutableBackground);
If I draw a line in the render method, it does indeed draw.. but on a black background. Strangely enough if I do
int myColor = mutableBackground.getPixel(100, 100);
int greeness = Color.green(myColor);;
Log.d(TAG, "Greeness - " + greeness);
The log shows.. Greeness - 255
So the bitmap is being colored green but it displays as black. This is really confusing me and I have to sort this out real soon.
Thanks anybody that can help.