Hey, i want to trace multi touch inputs. I am aware of the multitouch view demo in the asset library, but instead of creating new circles i want to be able to touch on different existing sprites and move them simultaneously.
Any ideas?
Multitouch
That demo shows how to detect multi-touch inputs.
You should be able to adapt it to check whether an input is inside a sprite's bounding rectangle.
My idea was to put an Area2D on the sprite, to detect when u hover over and combine with that given example code but Area2D will always be ignored when using input functions like unhandled input
- Edited
In a Godot 3 project, my player is a KinematicBody2D, and the enemies are RigidBody2D's. They currently have Polygon2D avatars, but I think they used to be Sprites. I use _unhandled_input() to detect mouse/touch inputs on the player and enemies. Player and enemies have collision shapes too, but I don't think that affects inputs.
- Edited
If i want to make my sprite selectable i need to use Area2D with CollisionShape2D, which will be ignored because of the _unhandled_input(), which is a singleton (from the demo).
If i use a RectButton instead and make my own little detect system like that:
func is_in_rect(pos, rect):
return pos.x > rect.position.x \
and pos.y > rect.position.y \
and pos.x < rect.end.x \
and pos.y < rect.end.y
I cant get the right mouse position because rect positions always has its origin in the top left corner.
I tried several other workarounds and failed i cant get it to work.
I hope someone can give me a hint
- Edited
Genie RectButton
Do you mean Rect2?
If rect is the Rect2, then this adjusts rect's position so that it's centered at Vector2(a, b):
rect.position = Vector2(a, b) - rect.size / 2
And you don't need to write your own is_in_rect() function. You can use Rect2.has_point():
https://docs.godotengine.org/en/4.2/classes/class_rect2.html#class-rect2-method-has-point