Godot Engine

Godot Engine

CambroNZ Feb 11, 2020 @ 4:59pm
Need help with an animated sprite
Hi there, I'm totally new to Godot and have no coding or programing experience, just been following some youtube tutorials. I'm making a basic pixel art game.

I have an Animated Sprite with frames for a door opening and I just want this animated sprite to play only once upon game start. So I take it off looping and the sprite plays once in the editor, I then go to play the game and the animated sprite doesn't play (as it already played in the editor?)
Is there a way where the sprite will trigger or play upon game start?
< >
Showing 1-4 of 4 comments
Matt [Linux] Feb 11, 2020 @ 5:32pm 
try using the function below in _ready() on your script for that node

func _ready(): $AnimatedSprite.play()
Last edited by Matt [Linux]; Feb 11, 2020 @ 5:34pm
CambroNZ Feb 11, 2020 @ 7:45pm 
I named the animated sprite Garagedooropen and the name of the animation is Opening so in the code would I have to put:

func _ready():
$Garagedooropen.play()

or leave it as

func _ready():
$AnimatedSprite.play()

and do I put this code in the script for the scene which the animated sprite is in or do I made a script on the animated sprite and put the code in there. I may have tried some of these earlier but I got an error message when I tried to run the game

Edit* I put in the script for the scene node:

func _ready():
$Garagedooropen.play()

and also tried:
func _ready():
$Garagedooropen.play("Opening")
but it still wouldnt play when I ran the game so instead I put in

func _ready():
$AnimatedSprite.play()

but it came up with error message so I tried:

func _ready():
$AnimatedSprite.play("Opening")

and it came up with the same error message which says:

"Attempt to call function 'play' in base 'null instance' on a null instance
Last edited by CambroNZ; Feb 11, 2020 @ 8:09pm
Sersch Feb 12, 2020 @ 3:57am 
Just to make sure you have not overlooked this small detail: you have to reset the animation in the editor to the first frame before you start your game, or the animation will play from the last frame and immediately stop.
CambroNZ Feb 12, 2020 @ 4:38am 
oh haha that did it XD thank you!
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Feb 11, 2020 @ 4:59pm
Posts: 4