From 6c82aba143d5b1a1641efd163a20508a18c1eb75 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 25 Feb 2023 18:46:19 +0100 Subject: [PATCH] support for green animation --- Characters/Villain.gd | 22 ++++++++++++++++++---- Characters/Villain.tscn | 9 +++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Characters/Villain.gd b/Characters/Villain.gd index 6f3b131..a39b596 100755 --- a/Characters/Villain.gd +++ b/Characters/Villain.gd @@ -5,8 +5,8 @@ onready var me = $AnimatedSprite onready var timer var limit_random var rng = RandomNumberGenerator.new() -onready var button = $"../Button/" -export(Array, String) var animations = ["orange", "red"] +onready var button = $"../Button" +export(Array, String) var animations = ["green", "orange", "red"] # True if animation should change var next = false @@ -14,10 +14,15 @@ var next = false # Called when the node enters the scene tree for the first time. func _ready(): - timer = 0 rng.randomize() + + reset_timer() + me.play(animations[0]) + + +func reset_timer(): + timer = 0 limit_random = rng.randi_range(2, 10) - me.play("orange") # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -38,6 +43,15 @@ func check_next_animframe(max_frame, next_animation): if me.frame == 0 and next: me.play(next_animation) next = false + if next_animation == animations[0]: + # Reset random for first animation + reset_timer() + return if max_frame == me.frame: # Last frame of animation reached next = true + return + if max_frame == -1 and timer >= limit_random: + # No frame in animation, use time + next = true + return diff --git a/Characters/Villain.tscn b/Characters/Villain.tscn index b9d3c6b..0798e2a 100755 --- a/Characters/Villain.tscn +++ b/Characters/Villain.tscn @@ -14,12 +14,17 @@ [sub_resource type="SpriteFrames" id=1] animations = [ { +"frames": [ ], +"loop": true, +"name": "green", +"speed": 5.0 +}, { "frames": [ ExtResource( 10 ), ExtResource( 9 ), ExtResource( 11 ) ], "loop": true, "name": "orange", "speed": 1.5 }, { -"frames": [ ExtResource( 1 ), ExtResource( 2 ), ExtResource( 8 ), ExtResource( 3 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ) ], +"frames": [ ExtResource( 1 ), ExtResource( 8 ), ExtResource( 2 ), ExtResource( 3 ), ExtResource( 5 ), ExtResource( 6 ), ExtResource( 7 ) ], "loop": true, "name": "red", "speed": 2.0 @@ -30,4 +35,4 @@ script = ExtResource( 4 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 1 ) -animation = "orange" +animation = "green"