我想沿SurfaceView
中的連續座標移動位圖圖像。我在繪製的位圖myBall
上SurfaceView
座標(x1, y1)
如下(部分代碼)(如何將位圖從一個座標移動到另一個座標 - Android開發
public class MainSurfaceView extends SurfaceView implements Runnable {...
...
@Override
public void run() {
while (isRunning) {
if (!myHolder.getSurface().isValid())
continue;
Canvas canvas;// Define canvas to paint on it
canvas = myHolder.lockCanvas();
//Draw full screen rectangle to hold the floor map.
Rect dest = new Rect(0, 0, getWidth(), getHeight());
Paint paint = new Paint();
paint.setFilterBitmap(true);
canvas.drawBitmap(bgImage, null, dest, paint);
//This is the ball I want to move
canvas.drawBitmap(myBall, x1, y1, null);
myHolder.unlockCanvasAndPost(canvas);
}
}
現在我想將它移動到(x2, y2)
然後(x3, y3)
和......多達必要和一前一後。我試圖使用TranslateAnimation
,但無法做到這一點
只是增加或減少(x1,y1)例如x1 = x1 + 5,y1 = y1 + 2 –
對不起Pradeep我沒有明白你的意思。如果我改變x1和y1的值,圖像將以不同的座標繪製。我想要的是從一個點到另一個點將它製作成動畫。謝謝! – Ermi