Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | marcorexo |
Hi,
I’m trying to animate 4 sprites in sequence:
- create a dictionary with keys numbering from 1 to 4 and values being the names of animated sprites:
sprites = {1:$sprite_top, 2:$sprite_right, 3:$sprite_bottom, 4:$sprite_left}
-
Create a sequence vector ranging from 1…4
-
I use a timer which calls a function that animates according to the sequence vector. The sprites animate at 1fps (3 frames) and the timer delay is set to 3s.
Code snippet:
var sequence
var flash_counter
func _ready():
#used to count the number of sprites to flash
flash_counter = 0
timer = $Timer
sequence = [1, 3, 2, 4]
#dictionary holding sprite sequence
sprites = {1:$sprite_top, 2:$sprite_right, 3:$sprite_bottom, 4:$sprite_left}
pass
func _draw():
flash_sequence(flash_counter)
pass
func flash_sequence(number):
sprites[sequence[number]].play()
flash_counter += 1
timer.start()
pass
func _on_Timer_timeout():
if(flash_counter != sequence.size()):
flash_sequence(flash_counter)
else:
timer.stop()
pass
The problem:
Though the function is called according to the timer and each sprite called in order, the sprites do not animate fully…not sure if there is some sort of discrepancy between the timer and sprite animation?
Why are you calling flash_sequence
from _draw()
AND in _on_Timer_timeout
?
_draw()
is called everytime the node visuals change, so it could be that your animation is being reset to the beginning because play()
got called from two places at a time.
Also, you don’t need to write pass
if the function is not empty.
Zylann | 2019-04-26 12:39