Desarrollo de juegos en android

I have been using Surfaceview For simple 2d racing car Development, as I come to know that using holder on canvas whole surface is redrawing, I want to redraw only car as physical position changed rather than lane, how to redraw only single component?

preguntado el 31 de julio de 12 a las 10:07

2 Respuestas

You could use bools within your onDraw. Within your onDraw you have a check such as

if(carMoved == false)
{
    // draw everything
}
else
{
    // draw your car
    carMoved = false; // this resets your onDraw so your whole canvas is re-drawn next time you invalidate()
}

There are proabably a lot of different ways that you can do it, however I feel this is the easiest way.

Respondido 16 Oct 13, 18:10

If you don't redraw more than just the car, it's not going to look right. At the mucho menos, you have to also draw over where the car was in the last frame. Otherwise it will show in both positions.

De la guía para desarrolladores:

Nota: En cada pasada que recupere el lienzo de SurfaceHolder, se conservará el estado anterior del lienzo. Para animar correctamente sus gráficos, debe volver a pintar toda la superficie. Por ejemplo, puede borrar el estado anterior del lienzo completando un color con drawColor () o configurando una imagen de fondo con drawBitmap (). De lo contrario, verá rastros de los dibujos que realizó anteriormente.

Respondido 16 Oct 13, 18:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.