我已经想出了如何使用坐标进行动画制作。我将解释什么,我没跳,这将是帮助他人: 首先,我保存的坐标点对象
List point_list = new ArrayList();
point_list.add(new Point(x_value, y_value));//Add the x and y coordinates to the Point\
休假实现Runnable和使用的onDraw()方法,而不是run()方法如下:
public class MainSurfaceView extends SurfaceView {...
....
@Override
protected void onDraw(Canvas canvas) {
// Draw full screen rectangle to hold the floor map.
Rect fArea = new Rect(0, 0, getWidth(), getHeight());
Paint paint = new Paint();
paint.setFilterBitmap(true);
// draw the paint on the rectangle with the floor map
canvas.drawBitmap(bgImage, null, fArea, paint);
// Get the coordinates of x & y as Point object
List myPoints = point_list;
// Start printing myBall on the floor (view)
try {
if (index < myPoints.size()) {
// Increment the value of index and use it as index for the point_list
index++;
}
// Print myBall in each coordinates of x & y using the index
canvas.drawBitmap(myBall, myPoints.get(index).x, myPoints.get(index).y, null);
} catch (IndexOutOfBoundsException e) {
// TODO: handle exception
}
}
我用try和catch来避免IndexOutOfBoundryExeption 干杯!