2013-06-18 76 views
2

我是Processing的新手,我想在Android模式下運行素描。我希望它能夠同時支持多種觸控。可以處理多點觸控嗎?

我在想,如果有人能指導我這個問題:

我怎樣才能讓我的素描支持多點觸控?

+0

我發現[用於處理多點觸摸庫](http://tillnagel.com/ 2011/06/simpletouch-multitouch-library-for-processing /)但我不知道自2011年以來它是否已經更新。 – user2468700

+0

看看這裏:http://www.tuio.org/?軟件 –

回答

6

下面是一個完整的例子:

/* 
* 
* 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); 
} 
1

上有加工的Android維基幾個鏈接在http://wiki.processing.org/w/Android

+0

那麼,另外,我的素描不能在JavaScript模式下運行:(不知道爲什麼,我有最新的JRE和JDK –

+0

好吧,但那是reall Ÿ單獨的問題。有很多原因可能導致它無法在JavaScript模式下運行,並且您沒有提供任何線索...... –