From 4c7038dd4a842400c1904de8b010183bd15b50bb Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 21 Nov 2021 23:29:05 +0100 Subject: [PATCH] fix hanafuda card lifetime --- HanafudaCard.gd | 7 ++++++- HanafudaCard.tscn | 12 +++++------- Main.tscn | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/HanafudaCard.gd b/HanafudaCard.gd index b42d3cd..c2955d4 100644 --- a/HanafudaCard.gd +++ b/HanafudaCard.gd @@ -33,9 +33,10 @@ enum Flower { export var revealed: bool = true setget reveal +onready var _is_ready := true + # Called when the node enters the scene tree for the first time. func _ready(): - $Backside/TextureRect.rect_global_position = $"Backside/Border sprite".get_rect() reveal(revealed) # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -44,6 +45,10 @@ func _process(delta): func reveal(new_reveal: bool): revealed = new_reveal + + if not _is_ready: + yield(self, "ready") + if revealed: print("Reveal card") $Frontside.show() diff --git a/HanafudaCard.tscn b/HanafudaCard.tscn index 1285ff7..78e1223 100644 --- a/HanafudaCard.tscn +++ b/HanafudaCard.tscn @@ -10,17 +10,16 @@ script = ExtResource( 1 ) revealed = false [node name="Frontside" type="Sprite" parent="."] -visible = false -scale = Vector2( 0.2, 0.2 ) texture = ExtResource( 2 ) [node name="Backside" type="Node2D" parent="."] +visible = false [node name="TextureRect" type="TextureRect" parent="Backside"] -margin_left = -91.0 -margin_top = -155.0 -margin_right = 809.0 -margin_bottom = 1380.0 +margin_left = -110.0 +margin_top = -193.0 +margin_right = 1000.0 +margin_bottom = 1722.0 rect_scale = Vector2( 0.2, 0.2 ) texture = ExtResource( 4 ) stretch_mode = 2 @@ -29,5 +28,4 @@ __meta__ = { } [node name="Border sprite" type="Sprite" parent="Backside"] -scale = Vector2( 0.2, 0.2 ) texture = ExtResource( 3 ) diff --git a/Main.tscn b/Main.tscn index 17ca5e7..63a79ce 100644 --- a/Main.tscn +++ b/Main.tscn @@ -2,7 +2,7 @@ [ext_resource path="res://HanafudaCard.tscn" type="PackedScene" id=1] -[node name="Node2D" type="Node"] +[node name="Node" type="Node"] [node name="Background" type="ColorRect" parent="."] anchor_right = 1.0 @@ -14,3 +14,4 @@ __meta__ = { [node name="HanafudaCard" parent="." instance=ExtResource( 1 )] position = Vector2( 205, 447 ) +revealed = true