I’m making an android app with multi touch and when a finger leaves the screen, I’d like to know which one it was because I’m tracking how long it has been since each started.
Can I do something like this:
void touchEnded(Touch t)
{
print(t.id);
}
Anybody know?
Thanks
noel
May 21, 2020, 6:14pm
2
Try and see if this code can help.
float[] old_x_touches;
float[] old_y_touches;
int tl;
boolean allow = true;
void setup() {
fullScreen();
orientation(PORTRAIT);
textFont(createFont("SansSerif", 24 * displayDensity));
textAlign(CENTER, CENTER);
}
void draw() {
if (allow) {
background(255);
for (int i = 0; i < touches.length; i++) {
float d = (100 + 100 * touches[i].area) * displayDensity;
fill(0, 255 * touches[i].pressure);
ellipse(touches[i].x, touches[i].y, d, d);
fill(255, 0, 0);
text(touches[i].id, touches[i].x + d/2, touches[i].y - d/2);
}
old_x_touches = new float[touches.length];
old_y_touches = new float[touches.length];
for (int i = 0; i < touches.length; i++) {
old_x_touches[i] = touches[i].x;
old_y_touches[i] = touches[i].y;
tl = touches.length;
}
for (int i = 0; i < touches.length; i++) {
text("Touch "+i+" is "+floor(touches[i].x)+" , "+ floor(touches[i].y), width/2, 50+i*50);
}
}
}
void mouseDragged() {
if (allow) {
background(255);
allow = false;
for (int i = 0; i < tl; i++) {
text("Last saved touches are "+floor(old_x_touches[i])+" , "+ floor( old_y_touches[i]), width/2, 50+i*50);
}
}
}
noel
December 18, 2020, 7:06pm
3
Sorry, posting on the wrong topic.