Find a pair init
This commit is contained in:
parent
35050d332a
commit
75603094bb
7 changed files with 133 additions and 61 deletions
|
@ -1,16 +1,52 @@
|
|||
extends Button
|
||||
extends Area2D
|
||||
|
||||
@onready var image := $Image
|
||||
signal tile_clicked(tile)
|
||||
|
||||
@export var front_texture: Texture2D # Изображение на лицевой стороне
|
||||
@export var back_texture: Texture2D # Изображение на обратной стороне
|
||||
@export var flip_duration: float = 0.3 # Длительность анимации переворота
|
||||
|
||||
@onready var sprite = $Sprite2D
|
||||
@onready var timer = $Timer
|
||||
|
||||
var is_flipped: bool = false
|
||||
var can_click: bool = true
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
sprite.texture = back_texture
|
||||
|
||||
func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
|
||||
if not can_click: return
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||
emit_signal ("tile_clicked", self)
|
||||
flip_tile()
|
||||
|
||||
func flip_tile():
|
||||
is_flipped = true
|
||||
can_click = false
|
||||
|
||||
# Анимация переворота
|
||||
var tween = create_tween()
|
||||
tween.tween_property(self, "scale:x", 0.0, flip_duration/2)
|
||||
tween.tween_callback(_change_texture)
|
||||
tween.tween_property(self, "scale:x", 1.0, flip_duration/2)
|
||||
timer.start()
|
||||
|
||||
func _change_texture():
|
||||
sprite.texture = front_texture if is_flipped else back_texture
|
||||
|
||||
func hide_tile():
|
||||
is_flipped = false
|
||||
|
||||
var tween = create_tween()
|
||||
tween.tween_property(self, "scale:x", 0.0, flip_duration/2)
|
||||
tween.tween_callback(_change_texture)
|
||||
tween.tween_property(self, "scale:x", 1.0, flip_duration/2)
|
||||
tween.tween_callback(_enable_click)
|
||||
|
||||
func _enable_click():
|
||||
can_click = true
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_pressed() -> void:
|
||||
image.show()
|
||||
func _on_timer_timeout() -> void:
|
||||
hide_tile()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue