FaC grid container
This commit is contained in:
parent
75603094bb
commit
3232182a9f
8 changed files with 67 additions and 51 deletions
50
scripts/find_a_couple/tile.gd
Normal file
50
scripts/find_a_couple/tile.gd
Normal file
|
@ -0,0 +1,50 @@
|
|||
extends TextureButton
|
||||
|
||||
@export var front_texture: Texture2D # Изображение на лицевой стороне
|
||||
@export var back_texture: Texture2D # Изображение на обратной стороне
|
||||
@export var flip_duration: float = 0.3 # Длительность анимации переворота
|
||||
|
||||
@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:
|
||||
texture_normal = back_texture
|
||||
|
||||
|
||||
func _on_button_down() -> void:
|
||||
if not can_click: return
|
||||
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():
|
||||
texture_normal = 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
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
hide_tile()
|
1
scripts/find_a_couple/tile.gd.uid
Normal file
1
scripts/find_a_couple/tile.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://dj8d1k52lircu
|
Loading…
Add table
Add a link
Reference in a new issue