Make animation use the queue to solve some annoying issues

This commit is contained in:
Hamcha 2019-05-16 23:41:09 +02:00
parent 384f6756fb
commit fb6a1a0dc9
Signed by: hamcha
GPG key ID: A40413D21021EAEE
5 changed files with 101 additions and 23 deletions

View file

@ -92,10 +92,10 @@ func _input_event(camera, event, click_position, click_normal, shape_idx):
# Check double click # Check double click
if event.doubleclick and not inHand and not lifted and not animation.is_playing(): if event.doubleclick and not inHand and not lifted and not animation.is_playing():
if exhausted: if exhausted:
animation.play_backwards("tap") animation.queue("tap-back")
exhausted = false exhausted = false
else: else:
animation.play("tap") animation.queue("tap")
exhausted = true exhausted = true
func clickable() -> bool: func clickable() -> bool:
@ -112,10 +112,10 @@ func _menu_action(id: int):
match id: match id:
0: # Flip 0: # Flip
if flipped: if flipped:
animation.play_backwards("flip") animation.queue("flip-back")
flipped = false flipped = false
else: else:
animation.play("flip") animation.queue("flip")
flipped = true flipped = true
func _check_drop_anim(anim_name): func _check_drop_anim(anim_name):

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2] [gd_scene load_steps=16 format=2]
[ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1] [ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1]
[ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2] [ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2]
@ -24,8 +24,35 @@ tracks/0/keys = {
"times": PoolRealArray( 0, 0.1 ) "times": PoolRealArray( 0, 0.1 )
} }
[sub_resource type="Animation" id=11]
resource_name = "drop-board"
length = 0.3
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath("..:translation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.3 ),
"transitions": PoolRealArray( 0.870551, 0.965936 ),
"update": 0,
"values": [ Vector3( 0, 0.15, 0 ), Vector3( 0, 0, 0 ) ]
}
tracks/1/type = "bezier"
tracks/1/path = NodePath("..:rotation_degrees:z")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"points": PoolRealArray( 0, -0.173703, -0.837245, 0.134235, 0.64701, -6.53051, -0.0617135, -2.00939, 0.0466494, 1.5189, 0, -0.0279863, -0.888281, 0.0279863, 0.888281 ),
"times": PoolRealArray( 0, 0.2, 0.3 )
}
[sub_resource type="Animation" id=3] [sub_resource type="Animation" id=3]
resource_name = "drop" resource_name = "drop-hand"
length = 0.1 length = 0.1
step = 0.05 step = 0.05
tracks/0/type = "value" tracks/0/type = "value"
@ -70,6 +97,35 @@ tracks/1/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 180 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 180 ) ]
} }
[sub_resource type="Animation" id=9]
resource_name = "flip-back"
length = 0.5
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath(".:translation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.25, 0.5 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0.01, 0 ), Vector3( 0, 0.5, 0 ), Vector3( 0, 0, 0 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath(".:rotation_degrees")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.5 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0, 180 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="Animation" id=5] [sub_resource type="Animation" id=5]
length = 0.1 length = 0.1
step = 0.01 step = 0.01
@ -125,6 +181,22 @@ tracks/0/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ]
} }
[sub_resource type="Animation" id=10]
resource_name = "tap-back"
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("..:rotation_degrees")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.3 ),
"transitions": PoolRealArray( 2.37841, 0.466516 ),
"update": 0,
"values": [ Vector3( 0, -90, 0 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="PlaneMesh" id=8] [sub_resource type="PlaneMesh" id=8]
[node name="Card" type="Area"] [node name="Card" type="Area"]
@ -143,11 +215,14 @@ material/0 = ExtResource( 3 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="CardModel/Border"] [node name="AnimationPlayer" type="AnimationPlayer" parent="CardModel/Border"]
anims/blur = SubResource( 2 ) anims/blur = SubResource( 2 )
anims/drop = SubResource( 3 ) anims/drop-board = SubResource( 11 )
anims/drop-hand = SubResource( 3 )
anims/flip = SubResource( 4 ) anims/flip = SubResource( 4 )
anims/flip-back = SubResource( 9 )
anims/focus = SubResource( 5 ) anims/focus = SubResource( 5 )
anims/lift = SubResource( 6 ) anims/lift = SubResource( 6 )
anims/tap = SubResource( 7 ) anims/tap = SubResource( 7 )
anims/tap-back = SubResource( 10 )
[node name="CardImage" type="MeshInstance" parent="CardModel/Border"] [node name="CardImage" type="MeshInstance" parent="CardModel/Border"]
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.009, 0 ) transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.009, 0 )

View file

@ -45,6 +45,7 @@ const CARD_DISTANCE = 0.01
func reorder_cards(): func reorder_cards():
var i := 0 var i := 0
var count := cards.size()
for card in cards: for card in cards:
card.translation.y = i*CARD_DISTANCE card.translation.y = (count-i)*CARD_DISTANCE
i += 1 i += 1

View file

@ -3,9 +3,9 @@
[ext_resource path="res://Scenes/Components/Stack.gd" type="Script" id=1] [ext_resource path="res://Scenes/Components/Stack.gd" type="Script" id=1]
[sub_resource type="BoxShape" id=1] [sub_resource type="BoxShape" id=1]
extents = Vector3( 0.424389, 0.024053, 0.546632 ) extents = Vector3( 0.424389, 0.0827175, 0.546632 )
[sub_resource type="SpatialMaterial" id=5] [sub_resource type="SpatialMaterial" id=2]
flags_transparent = true flags_transparent = true
flags_unshaded = true flags_unshaded = true
flags_vertex_lighting = true flags_vertex_lighting = true
@ -13,22 +13,23 @@ flags_do_not_receive_shadows = true
flags_disable_ambient_light = true flags_disable_ambient_light = true
albedo_color = Color( 1, 1, 1, 0.392157 ) albedo_color = Color( 1, 1, 1, 0.392157 )
[sub_resource type="DynamicFontData" id=2] [sub_resource type="DynamicFontData" id=3]
font_path = "res://UIAssets/Fonts/Catamaran-Bold.ttf" font_path = "res://UIAssets/Fonts/Catamaran-Bold.ttf"
[sub_resource type="DynamicFont" id=3] [sub_resource type="DynamicFont" id=4]
outline_size = 2 outline_size = 2
outline_color = Color( 0, 0, 0, 0.54902 ) outline_color = Color( 0, 0, 0, 0.54902 )
font_data = SubResource( 2 ) font_data = SubResource( 3 )
[sub_resource type="ViewportTexture" id=4] [sub_resource type="ViewportTexture" id=5]
viewport_path = NodePath("LabelViewport") viewport_path = NodePath("LabelViewport")
[node name="Stack" type="Area"] [node name="Stack" type="Area"]
input_ray_pickable = false
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."] [node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0239744, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0526529, 0 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="CSGBox" type="CSGBox" parent="."] [node name="CSGBox" type="CSGBox" parent="."]
@ -36,7 +37,7 @@ transform = Transform( 0.802373, 0, 0, 0, 1, 0, 0, 0, 0.81647, 0, 0, 0 )
width = 0.85 width = 0.85
height = 0.002 height = 0.002
depth = 1.15 depth = 1.15
material = SubResource( 5 ) material = SubResource( 2 )
[node name="CSGBox2" type="CSGBox" parent="CSGBox"] [node name="CSGBox2" type="CSGBox" parent="CSGBox"]
transform = Transform( 1.00679, 0, 0, 0, 1.00679, 0, 0, 0, 1.00679, 0, 0, 0 ) transform = Transform( 1.00679, 0, 0, 0, 1.00679, 0, 0, 0, 1.00679, 0, 0, 0 )
@ -67,13 +68,13 @@ usage = 0
[node name="Label" type="Label" parent="LabelViewport"] [node name="Label" type="Label" parent="LabelViewport"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
custom_fonts/font = SubResource( 3 ) custom_fonts/font = SubResource( 4 )
align = 1 align = 1
valign = 1 valign = 1
[node name="LabelSprite" type="Sprite3D" parent="."] [node name="LabelSprite" type="Sprite3D" parent="."]
transform = Transform( 0.5853, 0.810817, -3.54419e-008, 0, -4.37114e-008, -1, -0.810817, 0.5853, -2.55843e-008, 0, 0, 0 ) transform = Transform( 0.5853, 0.810817, -3.54419e-008, 0, -4.37114e-008, -1, -0.810817, 0.5853, -2.55843e-008, 0, 0, 0 )
texture = SubResource( 4 ) texture = SubResource( 5 )
region_rect = Rect2( 0, 0, 30, 30 ) region_rect = Rect2( 0, 0, 30, 30 )
[connection signal="mouse_entered" from="." to="." method="_mouse_entered"] [connection signal="mouse_entered" from="." to="." method="_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_mouse_exited"] [connection signal="mouse_exited" from="." to="." method="_mouse_exited"]

View file

@ -123,13 +123,14 @@ func _card_picked(card: Card):
if card.inZone: if card.inZone:
zones[card.zoneName].pop_card() zones[card.zoneName].pop_card()
holdingCard = card holdingCard = card
holdingCard.animation.play("lift") holdingCard.animation.queue("lift")
func _card_dropped(card: Card): func _card_dropped(card: Card):
if card.inHand: if card.inHand:
card.animation.play("drop") card.animation.queue("drop-hand")
reorder_hand(0)
else: else:
card.animation.play_backwards("lift") card.animation.queue("drop-board")
if currentZone != null: if currentZone != null:
card.inZone = true card.inZone = true
currentZone.push_card(card) currentZone.push_card(card)
@ -138,12 +139,12 @@ func _card_dropped(card: Card):
func _card_selected(card: Card): func _card_selected(card: Card):
if card.inHand and focusedCard == null: if card.inHand and focusedCard == null:
focusedCard = card focusedCard = card
card.animation.play("focus") card.animation.queue("focus")
func _card_unselected(card: Card): func _card_unselected(card: Card):
if focusedCard == card: if focusedCard == card:
focusedCard = null focusedCard = null
card.animation.play("blur") card.animation.queue("blur")
func reparent(object: Node, from: Node, to: Node): func reparent(object: Node, from: Node, to: Node):
from.remove_child(object) from.remove_child(object)