Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Button
- export var action: String
- var _touch_index : int = -1
- func _unhandled_input(event: InputEvent) -> void:
- if event is InputEventScreenTouch:
- if event.pressed:
- if _is_point_inside_area(event.position) and _touch_index == -1:
- _touch_index = event.index
- get_tree().set_input_as_handled()
- Input.action_press(action)
- elif event.index == _touch_index:
- Input.action_release(action)
- _reset()
- get_tree().set_input_as_handled()
- func _is_point_inside_area(point: Vector2) -> bool:
- var x: bool = point.x >= rect_global_position.x and point.x <= rect_global_position.x + (rect_size.x * get_global_transform_with_canvas().get_scale().x)
- var y: bool = point.y >= rect_global_position.y and point.y <= rect_global_position.y + (rect_size.y * get_global_transform_with_canvas().get_scale().y)
- return x and y
- func _reset():
- _touch_index = -1
Advertisement
Add Comment
Please, Sign In to add comment