support for green animation
This commit is contained in:
parent
a576058b01
commit
6c82aba143
2 changed files with 25 additions and 6 deletions
|
@ -5,8 +5,8 @@ onready var me = $AnimatedSprite
|
||||||
onready var timer
|
onready var timer
|
||||||
var limit_random
|
var limit_random
|
||||||
var rng = RandomNumberGenerator.new()
|
var rng = RandomNumberGenerator.new()
|
||||||
onready var button = $"../Button/"
|
onready var button = $"../Button"
|
||||||
export(Array, String) var animations = ["orange", "red"]
|
export(Array, String) var animations = ["green", "orange", "red"]
|
||||||
|
|
||||||
# True if animation should change
|
# True if animation should change
|
||||||
var next = false
|
var next = false
|
||||||
|
@ -14,10 +14,15 @@ var next = false
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
timer = 0
|
|
||||||
rng.randomize()
|
rng.randomize()
|
||||||
|
|
||||||
|
reset_timer()
|
||||||
|
me.play(animations[0])
|
||||||
|
|
||||||
|
|
||||||
|
func reset_timer():
|
||||||
|
timer = 0
|
||||||
limit_random = rng.randi_range(2, 10)
|
limit_random = rng.randi_range(2, 10)
|
||||||
me.play("orange")
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# 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:
|
if me.frame == 0 and next:
|
||||||
me.play(next_animation)
|
me.play(next_animation)
|
||||||
next = false
|
next = false
|
||||||
|
if next_animation == animations[0]:
|
||||||
|
# Reset random for first animation
|
||||||
|
reset_timer()
|
||||||
|
return
|
||||||
if max_frame == me.frame:
|
if max_frame == me.frame:
|
||||||
# Last frame of animation reached
|
# Last frame of animation reached
|
||||||
next = true
|
next = true
|
||||||
|
return
|
||||||
|
if max_frame == -1 and timer >= limit_random:
|
||||||
|
# No frame in animation, use time
|
||||||
|
next = true
|
||||||
|
return
|
||||||
|
|
|
@ -14,12 +14,17 @@
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id=1]
|
[sub_resource type="SpriteFrames" id=1]
|
||||||
animations = [ {
|
animations = [ {
|
||||||
|
"frames": [ ],
|
||||||
|
"loop": true,
|
||||||
|
"name": "green",
|
||||||
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
"frames": [ ExtResource( 10 ), ExtResource( 9 ), ExtResource( 11 ) ],
|
"frames": [ ExtResource( 10 ), ExtResource( 9 ), ExtResource( 11 ) ],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": "orange",
|
"name": "orange",
|
||||||
"speed": 1.5
|
"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,
|
"loop": true,
|
||||||
"name": "red",
|
"name": "red",
|
||||||
"speed": 2.0
|
"speed": 2.0
|
||||||
|
@ -30,4 +35,4 @@ script = ExtResource( 4 )
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 1 )
|
frames = SubResource( 1 )
|
||||||
animation = "orange"
|
animation = "green"
|
||||||
|
|
Reference in a new issue