Explorar o código

Merge pull request #505 from pkruszynski/mobile-multitouch-view-fix

Mobile multitouch view fix
Aaron Franke %!s(int64=5) %!d(string=hai) anos
pai
achega
913de13ec9

+ 5 - 5
mobile/multitouch_view/Main.gd

@@ -9,14 +9,14 @@ func _draw():
 	# Get the touch helper singleton.
 	var touch_helper = get_node("/root/TouchHelper")
 	# Draw every pointer as a circle.
-	for ptr_id in touch_helper.state.keys():
-		var pos = touch_helper.state[ptr_id]
-		var color = _get_color_for_ptr_id(ptr_id)
+	for ptr_index in touch_helper.state.keys():
+		var pos = touch_helper.state[ptr_index]
+		var color = _get_color_for_ptr_index(ptr_index)
 		color.a = 0.75
 		draw_circle(pos, 40.0, color)
 
 
 # Just a way of getting different colors.
-func _get_color_for_ptr_id(id):
-	var x = (id % 7) + 1
+func _get_color_for_ptr_index(index):
+	var x = (index % 7) + 1
 	return Color(float(bool(x & 1)), float(bool(x & 2)), float(bool(x & 4)))

+ 1 - 1
mobile/multitouch_view/README.md

@@ -1,6 +1,6 @@
 # Multitouch View with GDScript
 
-Simple debugger for multitouch input. Shows red dots everywhere you press.
+Simple debugger for multitouch input. Shows colored dots everywhere you press.
 
 Language: GDScript
 

+ 4 - 13
mobile/multitouch_view/TouchHelper.gd

@@ -1,29 +1,20 @@
 extends Node
 # This will track the position of every pointer in its public `state` property, which is a
-# Dictionary, in which each key is a pointer id (integer) and each value its position (Vector2).
+# Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2).
 # It works by listening to input events not handled by other means.
 # It also remaps the pointer indices coming from the OS to the lowest available to be friendlier.
 # It can be conveniently setup as a singleton.
 
 var state = {}
-var _os2own = {}
 
 func _unhandled_input(event):
 	if event is InputEventScreenTouch:
 		if event.pressed: # Down.
-			if !_os2own.has(event.index): # Defensively discard index if already known.
-				var ptr_id = state.size()
-				state[ptr_id] = event.position
-				_os2own[event.index] = ptr_id
+			state[event.index] = event.position
 		else: # Up.
-			if _os2own.has(event.index): # Defensively discard index if not known.
-				var ptr_id = _os2own[event.index]
-				state.erase(ptr_id)
-				_os2own.erase(event.index)
+			state.erase(event.index)
 		get_tree().set_input_as_handled()
 		
 	elif event is InputEventScreenDrag: # Movement.
-		if _os2own.has(event.index): # Defensively discard index if not known.
-			var ptr_id = _os2own[event.index]
-			state[ptr_id] = event.position
+		state[event.index] = event.position
 		get_tree().set_input_as_handled()

BIN=BIN
mobile/multitouch_view/screenshots/multitouch.png


+ 4 - 13
visual_script/multitouch_view/TouchHelper.gd

@@ -1,29 +1,20 @@
 extends Node
 # This will track the position of every pointer in its public `state` property, which is a
-# Dictionary, in which each key is a pointer id (integer) and each value its position (Vector2).
+# Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2).
 # It works by listening to input events not handled by other means.
 # It also remaps the pointer indices coming from the OS to the lowest available to be friendlier.
 # It can be conveniently setup as a singleton.
 
 var state = {}
-var _os2own = {}
 
 func _unhandled_input(event):
 	if event is InputEventScreenTouch:
 		if event.pressed: # Down.
-			if !_os2own.has(event.index): # Defensively discard index if already known.
-				var ptr_id = state.size()
-				state[ptr_id] = event.position
-				_os2own[event.index] = ptr_id
+			state[event.index] = event.position
 		else: # Up.
-			if _os2own.has(event.index): # Defensively discard index if not known.
-				var ptr_id = _os2own[event.index]
-				state.erase(ptr_id)
-				_os2own.erase(event.index)
+			state.erase(event.index)
 		get_tree().set_input_as_handled()
 		
 	elif event is InputEventScreenDrag: # Movement.
-		if _os2own.has(event.index): # Defensively discard index if not known.
-			var ptr_id = _os2own[event.index]
-			state[ptr_id] = event.position
+		state[event.index] = event.position
 		get_tree().set_input_as_handled()