fix(objects): replace Area2D.input_event with _input() for reliable Android touch
Area2D.input_event is unreliable on Android with gl_compatibility renderer. Switched to manual _input() hit detection using canvas_transform coordinate conversion, consistent with the DragDropComponent approach already used in this project. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
## ElevatorButton — tappable button that navigates the camera to a target floor.
|
||||
class_name ElevatorButton extends Node2D
|
||||
|
||||
const BUTTON_HALF_SIZE: float = 40.0
|
||||
|
||||
@export var target_floor: int = 0
|
||||
|
||||
var _area: Area2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_area = get_node_or_null("CollisionArea") as Area2D
|
||||
if _area != null:
|
||||
_area.input_event.connect(_on_input_event)
|
||||
|
||||
|
||||
func _on_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
_on_pressed()
|
||||
elif event is InputEventScreenTouch and event.pressed:
|
||||
func _input(event: InputEvent) -> void:
|
||||
var screen_pos: Vector2
|
||||
if event is InputEventScreenTouch and event.pressed:
|
||||
screen_pos = event.position
|
||||
elif event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
screen_pos = event.position
|
||||
else:
|
||||
return
|
||||
var canvas_transform: Transform2D = get_viewport().get_canvas_transform()
|
||||
var world_pos: Vector2 = canvas_transform.affine_inverse() * screen_pos
|
||||
var local_pos: Vector2 = to_local(world_pos)
|
||||
if abs(local_pos.x) <= BUTTON_HALF_SIZE and abs(local_pos.y) <= BUTTON_HALF_SIZE:
|
||||
_on_pressed()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user