能加工处理的多点触控? [英] Can Processing handle multi-touch?

查看:142
本文介绍了能加工处理的多点触控?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来处理,我想在Android的模式下运行我的草图。我希望它同时支持多点触摸。

I am new to Processing and I would like to run my sketch in Android mode. I want it to support multiple touches simultaneously.

我在想,如果有人能指导我这个问题:

I was wondering if someone can guide me on this question:

我怎样才能让我的素描支持多点触摸?

推荐答案

下面是一个完整的例子:

Here is a full example:

/*
 *
 * androidMultiTouch.pde
 * Shows the basic use of MultiTouch Events
 *
 */

//-----------------------------------------------------------------------------------------
// IMPORTS

import android.view.MotionEvent;


//-----------------------------------------------------------------------------------------
// VARIABLES

int TouchEvents;
float xTouch[];
float yTouch[];
int currentPointerId = 0;
boolean printFPS;


//-----------------------------------------------------------------------------------------

void setup() {
  size(displayWidth, displayHeight);
  orientation(LANDSCAPE);
  background(0, 255, 0);
  fill(0, 0, 244);
  rect(100, 100, 100, 100);
  stroke(255);

  // Initialize Multitouch x y arrays
  xTouch = new float [10];
  yTouch = new float [10]; // Don't use more than ten fingers!

}

//-----------------------------------------------------------------------------------------

void draw() {
  background(255, 0, 0);

  for (int i = 0; i < xTouch.length; i++) {
    ellipse(xTouch[i], yTouch[i], 150, 150);
  }

}

//-----------------------------------------------------------------------------------------

public boolean surfaceTouchEvent(MotionEvent event) {

  // Number of places on the screen being touched:
  TouchEvents = event.getPointerCount();

  // If no action is happening, listen for new events else 
  for (int i = 0; i < TouchEvents; i++) {
    int pointerId = event.getPointerId(i);
    xTouch[pointerId] = event.getX(i); 
    yTouch[pointerId] = event.getY(i);
    float siz = event.getSize(i);
  }

  // ACTION_DOWN 
  if (event.getActionMasked() == 0 ) {
    print("Initial action detected. (ACTION_DOWN)");
    print("Action index: " +str(event.getActionIndex()));
  } 
  // ACTION_UP 
  else if (event.getActionMasked() == 1) {
    print("ACTION_UP");
    print("Action index: " +str(event.getActionIndex()));
  }
  //  ACTION_POINTER_DOWN 
  else if (event.getActionMasked() == 5) {
    print("Secondary pointer detected: ACTION_POINTER_DOWN");
    print("Action index: " +str(event.getActionIndex()));
  }
  // ACTION_POINTER_UP 
  else if (event.getActionMasked() == 6) {
    print("ACTION_POINTER_UP");
    print("Action index: " +str(event.getActionIndex()));
  }
  // 
  else if (event.getActionMasked() == 4) {

  }

  // If you want the variables for motionX/motionY, mouseX/mouseY etc.
  // to work properly, you'll need to call super.surfaceTouchEvent().
  return super.surfaceTouchEvent(event);
}

这篇关于能加工处理的多点触控?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆