如何声明一组点的对象移动到和从?(Android / Java)



我想做的是创建一个手写应用程序,允许一个人按下对象(圆圈)并在设定的路径上向上/向下移动它。如果用户到达最低点,则创建另一个圆形对象,并创建另一组点,以此类推。

到目前为止,我有一个onTouch事件,它将我的ImageView对象(圆圈)移动到手指在触摸屏上的任何位置。

https://gist.github.com/Temptex/9796403

我怎么能让我的ImageView(圆)对象从点A -> B顺利使用onTouch事件?

编辑:我所问的一个图片示例:https://i.stack.imgur.com/9kSfe.jpg

为它创建了一个算法。

创建一个包含x个整数和y个整数的数组,并使用for循环检查对象是否过高(y坐标超出边界),并检查y和x是否超出数组的边界。

如果超出整数数组的范围,则将其设置为当前x/y数组值。在for循环中

如果这对任何人都有帮助,这里是代码:

private final int yCoOrdinate[] = {310, 360, 410};
private final int xCoOrdinate[] = {905, 890, 875};
// Get finger position
int x = (int)event.getRawX();
int y = (int)event.getRawY();
// View x/y co-ordinate on TextView
coordinates.setText("X = " + x + " - Y = " + y);
for(int i = 0; i < yCoOrdinate.length; i++) {
    // If object is to high set it to yCoOrdinate[0]                
    if(y <= yCoOrdinate[0]) {
        y = yCoOrdinate[0];
    }
    // Checks top left corner of A              
    if(y == yCoOrdinate[0] && x <= xCoOrdinate[0]) {
        x = xCoOrdinate[0];
        Log.d("Coordinate check", "X = " + x + "Y = " + y);
    // Checks if current x/y position if out of bounds and sets them to i
    } else if (y <= yCoOrdinate[i] && x <= xCoOrdinate[i]) {
        y = yCoOrdinate[i];
        x = xCoOrdinate[i];
        Log.d("Coordinate check", "X = " + x + "Y = " + y);
    }
}

我现在可以用in bounds来控制我的ImageView

最新更新