开发者

When translating a matrix used to draw a bitmap, it draws multiple bitmaps

In my Android project, I have a matrix that I use to draw a bitmap on a canvas. During my drawFrame method, I translate the matrix in the Y direction so it looks like the bitmap is moving up. It does move up, but it is also drawn in the previous position leaving multiples of itself behind. Here is my drawFrame code:

Canvas canvas = null;
canvas = holder.lockCanvas();

Matrix moveMatrix = new Matrix ();
moveMatrix.postTranslate(0, 10);
matrix.preConcat(moveMatrix);

canvas.drawBitmap(bitmap, matrix, null);

holder.unlockCanvasAndPost(canvas);

"matrix" is a global Matrix member.

Does anyone know why this leaves a "streaking" trail of bitmaps across the screen?

Thanks!

I forgot to mention that each previous bit开发者_如何学Pythonmap position seems to shift up and down in the y direction every time the bitmap moves. So it ends up with a string of bitmaps that look like they are jittering up and down. This would mean that every bitmap would have to be redrawn every frame otherwise they would all be standing still.


You need to clear the Canvas at the previous position of the bitmap :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜