Android: Problem when drawing the same bitmap over and over on canvas?

I just wanted to say that I had an issue where the images on my canvas were flashing back and forth, or, flashing between black and my first frame until I made a movement, almost as if the canvas was rapidly switching between its current and last image.

I just wanted to say that I had an issue where the images on my canvas were flashing back and forth, or, flashing between black and my first frame until I made a movement, almost as if the canvas was rapidly switching between its current and last image. This might have had something to do with your situation, and to fix it I found out that it was because I was locking the canvas every frame, even when I had nothing to draw. For whatever reason, that lock, I think, created this situation.

I got around it by doing something like this: if (needToRedraw == true) { canvas = mSurfaceHolder. LockCanvas(null); ... logic to eventually draw on that canvas ... }.

Before canvas. DrawBitmap(...) call; try to use canvas. DrawColor(Color.

BLACK) to clear the Canvas from previous drawings. Sample code: // Stuff. Canvas.

DrawColor(Color. BLACK); canvas. DrawBitmap(wave.

GetSubWave(j), subWaveEdge, 40, brush); // Stuff.

Viktor Lannér, Thank you for helping, but I don't think that's the problem. I understand it is hard to read my codes since it is only a small piece of the big program. However, I found the problem: This is not mentioned in my original question, but in order to simulate the two waves moving after one another, I have to draw the next wave as soon as the first wave enters the screen.

However, each wave is longer than the width of the screen. Therefore, I have to draw the next wave from "outside" the screen if you know what I mean. It means that the next wave is drawn from a negative x-coordinate from outside the screen: // If the wave has passed the left edge of the screen then add a new sub-wave.

If (wave.getFarthestEdge() >= 0) wave. AddSubWaveEdges(wave.getFarthestEdge() - this.getWidth()); And I found out that it does not like this. This is what causes the flashing back and forth.In order to fix this, instead of drawing the next wave from outside the screen, I use this method: canvas.

DrawBitmap (Bitmap bitmap, Rect source, Rect destination, Paint paint) This method allows you to specify a rectangular region on the bitmap to be drawn to the screen and a rectangular region on the screen where that part of the bitmap will be drawn over. I use this method to draw the next wave.As the next wave moves into the screen, I change the "source" and "destination" appropriately to draw parts of the bitmap.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions