LoginSignup
0
2

More than 5 years have passed since last update.

processing(android mode)におけるtouchesのバグとその対処法

Last updated at Posted at 2018-09-29

はじめに

processingのtouchesとはPointer型の配列として現在タッチされている点の座標等を保存しています
Pointerクラスは


public class Pointer {
  public int id;
  public float x, y;
  public float area;
  public float pressure;
}

となっています

BUGの内容

一つ目の指を一切動かさずタップし続け、二つ目の指を押して離したとき二つ目の指が離れたことを認識しません

BUGの解決法

touchesを自分で作成してしまいます
具体的には


import android.view.*;
import java.util.ArrayList; 
import java.util.Collections; 
import java.util.List;
Pointer[] touches;
List<Pointer> touchesList=Collections.synchronizedList(new ArrayList<Pointer>());
@Override
public boolean surfaceTouchEvent(MotionEvent event) {
  int count=event.getPointerCount();
  int action=event.getAction();
  int actionMasked = action & MotionEvent.ACTION_MASK;
  int idx = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
  boolean flag = actionMasked==MotionEvent.ACTION_UP||actionMasked==MotionEvent.ACTION_POINTER_UP;
  touchesList.clear();
  for(int i=0;i<count;i++){
    if(flag&&idx==i)continue;
    Pointer t=new Pointer();
    t.id=event.getPointerId(i);
    t.x=event.getX(i);
    t.y=event.getY(i);
    t.area=event.getSize(i);
    t.pressure=event.getPressure(i);
    touchesList.add(t);
  }
  return super.surfaceTouchEvent(event);
}
class Pointer {
  public int id;
  public float x, y;
  public float area;
  public float pressure;
}

というコードを書いたあとvoid draw{…}にて


touches = touchesList.toArray(new Pointer[touchesList.size()]);

と書いてListを配列に変換します

あとがき

やはりprocessingは複雑な処理には向かないというのが正直な感想です
ただ、processingでは実現が大変なことに対してprocessingのコードを読み込んで解決法を見出すことは勉強になるし、何より楽しいです

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2