51 lines
1.6 KiB
GDScript
51 lines
1.6 KiB
GDScript
extends CanvasLayer
|
|
|
|
|
|
## Controles táctiles provisionales para jugar en móvil.
|
|
##
|
|
## Los botones no llaman directamente al Player. En su lugar pulsan y liberan
|
|
## las mismas acciones del InputMap que ya usa el teclado. De esta forma la
|
|
## lógica de movimiento/combate sigue teniendo una única fuente de entrada:
|
|
##
|
|
## teclado -> InputMap <- controles táctiles
|
|
## |
|
|
## Player
|
|
##
|
|
## Cuando llegue el arte definitivo, esta escena puede cambiar por completo sin
|
|
## tocar player.gd mientras conserve estas cuatro acciones.
|
|
|
|
@onready var move_left_button: Button = $Controls/MoveLeft
|
|
@onready var move_right_button: Button = $Controls/MoveRight
|
|
@onready var jump_button: Button = $Controls/Jump
|
|
@onready var attack_button: Button = $Controls/Attack
|
|
|
|
|
|
func _ready() -> void:
|
|
_bind_button(move_left_button, &"move_left")
|
|
_bind_button(move_right_button, &"move_right")
|
|
_bind_button(jump_button, &"jump")
|
|
_bind_button(attack_button, &"attack")
|
|
|
|
|
|
func _exit_tree() -> void:
|
|
# Si la escena cambia mientras un dedo sigue apoyado, Godot puede no llegar
|
|
# a emitir button_up. Liberamos las acciones para no dejar una tecla virtual
|
|
# atascada al cargar la siguiente escena.
|
|
Input.action_release(&"move_left")
|
|
Input.action_release(&"move_right")
|
|
Input.action_release(&"jump")
|
|
Input.action_release(&"attack")
|
|
|
|
|
|
func _bind_button(button: Button, action: StringName) -> void:
|
|
button.button_down.connect(_press_action.bind(action))
|
|
button.button_up.connect(_release_action.bind(action))
|
|
|
|
|
|
func _press_action(action: StringName) -> void:
|
|
Input.action_press(action)
|
|
|
|
|
|
func _release_action(action: StringName) -> void:
|
|
Input.action_release(action)
|