android 坐标对象,如何将位图从一个坐标移动到另一个坐标 - Android开发

我已经想出了如何使用坐标进行动画制作。我将解释什么,我没跳,这将是帮助他人: 首先,我保存的坐标点对象

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 干杯!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值