0

我正在使用 Processing 进行编程,我需要的是 pmouseX/Y 的等价物,但用于触摸,但我不能使用 pmouse,因为我使用多点触控,并且我需要每个触摸点的先前坐标。我不知道我是否说清楚了,举个例子,我需要知道滑动的初始坐标和最终坐标

我目前用来获取初始坐标:

    public boolean surfaceTouchEvent(MotionEvent me) {
    float x0=me.getX(0);
    float y0=me.getY(0);
    ....
    ....
    return super.surfaceTouchEvent(me);
    }
4

1 回答 1

0

我不确定我是否在这里得到你的权利,因为这似乎是非常基本的编程,但我会尝试。

只需使用 ArrayList 并在那里添加每个位置。对于不同的触摸,您可能需要使用 HashMap,如下所示:

HashMap<MotionEvent, ArrayList<Point2D.Float>> touches = new HashMap<MotionEvent, ArrayList<Point2D.Float>>();

public boolean surfaceTouchEvent(MotionEvent me)
{
    float x0=me.getX(0);
    float y0=me.getY(0);
    if (!touches.containsKey(me))
    {
        touches.add(me, new ArrayList<Point2D.Float>());
    }
    else
    {
        // get previous position
        Point2D.Float prevpos = touches.get(me).get(touches.get(me).size() - 1);
    }
    touches.get(me).add(new Point2D.Float(x0, y0));
    ....
}

没有对此进行测试,但这基本上就是它的工作方式。

于 2012-05-09T14:34:18.140 回答