Touch questions, since documentation isn't as robust


#1

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.


#2

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)
https://developer.playcanvas.com/en/api/pc.TouchEvent.html
https://developer.playcanvas.com/en/api/pc.Touch.html

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


#3

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