down votefavorite
<http://stackoverflow.com/questions/37489608/android-canvas-is-saving-previous-state-when-object-is-moving#>
Here's my problem:
When rendering an object which has speed (ie it's moving), the last frame
of the object is also drawn, meaning that instead of a nice moving
animation, I end up with the object drawn multiple times across its
movement path.
Here is my render method (in the game loop):
private void render() {
//if the surface is NOT valid, exit rendering
if (!surfaceHolder.getSurface().isValid()){
return;
}
//lock the canvas
canvas = surfaceHolder.lockCanvas();
//draw all game objects to canvas (only 1 object atm)
wizard.render(canvas);
//unlock and post the canvas
surfaceHolder.unlockCanvasAndPost(canvas);}
and the wizard render:
public void render(Canvas canvas) {
canvas.drawBitmap(spriteSheet, position.x, position.y, null);}
As far as I know, between each unlock and lock of the surface, its contents
are not preserved, meaning that it is completely redrawn each time the
render function is called:
"The content of the Surface is never preserved between unlockCanvas() and
lockCanvas(), for this reason, every pixel within the Surface area must be
written." ~ taken from the documentation
So why isn't this happening? Why is the canvas not being re-drawn and
instead is preserving all of the wizard's frames?
Thanks in advance! ^_^
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/a945d8e9-5db8-4806-8304-75d5d1220fe4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.