Touch questions, since documentation isn't as robust

I have few simple questions.

How would I go about getting the index number of a touch that hits say a specific object or area on the screen.

Example: A button on the bottom left, or anywhere on the left side of the devices screen, being pressed by the 2nd touch (index 1), with the 1st touch somewhere completely different holding another button or area.

Or is there a better solution to this problem I’ll lay out below.

Once I press a button or touch an area of the screen I then want every movement of that specific touch to determine the variables attached to what it touched. Ignoring what the other touch inputs will do moving forward. Whether they are touching or moving etc.

Example: A touch screen joystick.

Just would like to no more about the internal workings of touch within Playcanvas.

There’s a couple of ways depending on which event you are listening to.

If it’s a standard pc.EVENT_TOUCH_* , then you can get the ids via touches or changedTouches (see id)

If you are getting the event from clicking on an element, it’s a bit trickier as you have to go through the browser touch event via changedTouches and touches (see identifier)

https://developer.playcanvas.com/en/api/pc.ElementTouchEvent.html

1 Like

I found a solution to this problem.

I just do a for loop and look for the specific ‘id’ and ‘array element’, and works the way I hoped for.

I also tried the array.find() javascript method and it gets weird or I just didn’t understand what was happening.

Either way the for loop works just fine. :smiley: thanks