【发布时间】:2014-01-08 03:07:45
【问题描述】:
我想沿SurfaceView 中的连续坐标移动位图图像。我在SurfaceView 上的坐标(x1, y1) 上绘制了一个位图myBall,如下(部分代码)(
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 的值,图像将以不同的坐标绘制。我想要的是从一个点到下一个点的动画。提前谢谢!
标签: android animation bitmap surfaceview