How to do multiple touches on screen?


I have been making a game on Android and I wanted to know how to make multiple touches on the screen. For example I created two buttons. The first is for running and the second is for jumping. I wanted to know how to run and jump at the same time because you normally cant have 2 different mouseX and mouseY positions at the same time right? I hope you understand what I mean, thank you

You can use touches. With touches.length you can get how many touches are on your display and with touches[i].x and touches[i].y you can get the position of the touch i.
Warning: touches[i] does not return a PVector. It returns a pointer (processing.event.TouchEvent.Pointer) but you can just convert it with PVector v = new PVector(touches[0].x, touches[0].y).
Here a basic program to test this:

void setup() {

void draw() {
  for(int i = 0; i < touches.length; i++)
    point(touches[i].x, touches[i].y);

Good luck with your project!

1 Like

Thank you, it works now!:grin::+1:

1 Like

Fantastic and creative

1 Like