#Game Over Screen Animation Issue

12 messages · Page 1 of 1 (latest)

full bear
#

I created a CanvasLayer2D called Game Over Screen to make a game over screen which contains a restart button and a animation when the scene is played. In my World script I made so when the player dies the it will add the child Game Over Screen to the World scene using a PackedScene, though when I die it the Game Over Screen doesn't show any of my animations and just shows a restart button. How fix this issue where my animations are not playing when my World script adds the Game Over Screen scene to my World scene?

Code for World scene below:

extends Node2D

const PlayerScene = preload("res://src/Player.tscn")

export var game_over : PackedScene

onready var camera := $Camera2D
onready var player := $Player

var player_spawn_location = Vector2.ZERO

func _ready():
    player.connect_camera(camera)
    player_spawn_location = player.global_position
 
func _physics_process(_delta):
    if player.health <= 0:
        var game_over_screen = game_over.instance()
        get_tree().current_scene.add_child(game_over_screen)
lavish glade
#

I don't see anything that stops an animation

#

Is there any code in the game over screen?

full bear
#

yeah

extends CanvasLayer

func _on_Text_animation_finished(_anim_name):
    $Red_ball.play("Anger")

func _on_Red_ball_animation_finished(_anim_name):
    $Red_ball.play("Anger Loop")

func _on_Retry_Button_pressed():
    get_tree().reload_current_scene()
#

The animations works when I play the Game Over Screen scene by itself but with my World script adding the Game Over Screen to the World scene the Game Over Screen does not play its animations.

lavish glade
#

that's weird

dim glacier
#

i'm not sure you'd see an animation there at all - because you're adding game over screens in _physics_process() - repeatedly adding more and more game over screens, which may be showing one frame , then getting covered by another screen

full bear
#

Oh crap I didn't even think of that

#

so I can I make this appear once?

#

Maybe a function could work

dim glacier
#

you'd probably want changing the health value on the player to perhaps emit a signal in which you run a function to instance the game_over screen, so that you react to something that happens once rather than something that will run every physics frame

full bear
#

That sounds like a great idea Ill let you know if I have any trouble