FaC grid container
This commit is contained in:
parent
75603094bb
commit
3232182a9f
8 changed files with 67 additions and 51 deletions
|
@ -1,52 +0,0 @@
|
|||
extends Area2D
|
||||
|
||||
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
|
||||
|
||||
func _ready() -> void:
|
||||
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
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
hide_tile()
|
Loading…
Add table
Add a link
Reference in a new issue