2012-05-02 73 views
0

我在使用Processing进行编程,我需要的是相当于pmouseX/Y但是用于触摸,但我不能使用pmouse,因为我使用多点触控,而且我需要每个之前的坐标接触点。我不知道我是否说清楚了,做一个例子,我需要知道刷卡以前坐标的触摸对象

我目前使用获得初始坐标的最初和最终的坐标:

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

回答

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)); 
    .... 
} 

没有测试这一点,但基本上它是如何工作的。

+0

确保你清理完自己后,当然是 –

+0

当然:)只是懒惰 – jimpic

+0

是的,谢谢,我的问题基本上是了解Android如何处理这些情况,这是因为processing.org“隐藏”了很多东西。再次感谢你,我会尝试 – cifz