How to use "InputEventScreenTouch" for get many fingers position?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By klaoye

I want make a controller about mutil touch.(three fingers touch screen as meanwhile)
What I want to get second finger’s position when I using function"InputEventScreenTouch::get_position", but I only got first finger’s position and also “index” is 2.
I`m so sorry for my English,but I must to searching some solution for this problem.
Thanks very much.

:bust_in_silhouette: Reply From: Wakatta
var first_pointer_position
var second_pointer_position
var third_pointer_position

func _input(event):
    if event is InputEventScreenTouch:
        match event.get_index():
            0: 
                 #first pointer
                 first_pointer_position = event.position
            1: 
                 #second pointer if any
                 second_pointer_position = event.position
            2: 
                 #third pointer if any
                 third_pointer_position = event.position

Now you could create a var in global space for each pointer position and assign them each in their designated block like the above code or you could do the following

var pointers = {}

func _input(event):
    if event is InputEventScreenTouch or event is InputEventScreenDrag:
        pointers[event.get_index()] = event
      

Then access it like this

#Second pointer position 
pointers[1].position

You can even take it a step further and use an enum to avoid confusion

enum {FIRST, SECOND, THIRD, FORTH}
pointers[THIRD].position