0 votes

Hi there I am glad to be here. I am new to Godot and normally I come from the theater and I am doing 3D stuff. But now I tried out this game engine, and I love it. But I have a problem since two days, as written above. Although a function is working, and the debugger has no warnings or so, the engine "jumps" one code - line. The code is this one:

func toedlich():
if isalive == true:
$AnimatedSprite.play("Dumm
gelaufen")
yield($AnimatedSprite, "animationfinished")
is
alive = false
queue_free()

everything is executed, except the line with the AnimatedSprite. It even holds the yield for the time, the animation would need to run. But it does not play it.... I am absolutely confused. If there are any ideas, thank you very very much...
tellheim
(Sorry for the English, its not my mother language...)

Godot version 3.2.3 stable
in Engine by (12 points)

i suppose the issue is in the node, not the code, what parameter are you trying to animate?

the node is a kinematic body. maybe it is better to understand, if I post the whole code:
for explanation: "Flint" is the player

extends KinematicBody2D

export var gravity = 400
var movement = Vector2()
var UPVector = Vector2(0, -1)
export var speed = 200
export var jump = 250
onready var spriteFlint = $AnimatedSprite
var is
alive = true

--> signale

func onHarmlosArea2Dbodyentered(body: Node) -> void:
is_alive = false
harmlos()

func onHitBoxBombareaentered(area: Area2D) -> void:
is_alive = false
toedlich()

<--- Ende signale

-----> Physics Prozesse Flint

func physicsprocess(delta):
movement.x = 0
movement.y += gravity * delta

--> Verhindert, dass Gravitation sich multipliziert oder dass man an der Decke kleben bleibt

if is_on_ceiling() or is_on_floor():
    movement.y = 0

<-- Ende verhindert, dass Gravitation sich multipliziert oder dass man an der Decke kleben bleibt

_check_key_input()

movement = move_and_slide(movement, UP_Vector)

<-----Ende Physics Prozesse Flint

--> funktionen

func toedlich():
if isalive == false:
spriteFlint.play("Dumm
gelaufen")
yield(spriteFlint, "animationfinished")
is
alive = true
die()

func harmlos():
if isalive == false:
spriteFlint.play("Flint
Faellt")
yield(spriteFlint, "animationfinished")
is
alive = true

------> Steuerung Flint

func checkkey_input():

if Input.is_action_pressed("walk_left") && is_alive == true:
    spriteFlint.flip_h = true
    movement.x = -speed
if Input.is_action_pressed("walk_left") && is_on_floor() && is_alive == true:
    spriteFlint.flip_h = true
    movement.x = -speed
    spriteFlint.play("Flint_Walk")
if Input.is_action_pressed("walk_right") && is_alive == true:
    spriteFlint.flip_h = false      
    movement.x = speed
if Input.is_action_pressed("walk_right") && is_on_floor() && is_alive == true:
    spriteFlint.flip_h = false      
    movement.x = speed
    spriteFlint.play("Flint_Walk")
if Input.is_action_pressed("jump") && is_on_floor() && is_alive == true:
    movement.y = -jump
    spriteFlint.play("Flint_Jump")
if movement.y > 10:
    spriteFlint.play("Flint_Jump")
#if Input.is_action_pressed("up") && is_on_floor() && is_alive == true:
    #movement.y = -jump / 2
    #spriteFlint.play("Flint_Climb_Up")
if movement.x == 0 && movement.y == 0 && is_on_floor() && is_alive == true:
    spriteFlint.play("Flint_Idle")

<----Ende Steuerung Flint

func die() -> void:
SpielerDaten.deaths += 1
queue_free()

2 Answers

0 votes

Please check if AnimatedSprite is set to frame 0 in the editor. Sometimes people test animation in the editor and leave it on last frame, so it is impossible to see animation when calling play() form code.

by (5,252 points)

It is on frame 0. I always put all the animation in a AnimatedSprite back to 0. All other animations of that sprite are played...
maybe my signals are not correct? Did I misunderstand something?

But the signals are executing the function and the function plays everything except the sprite Animation in this case... makes me confused....

Thank you for taking the time... yes, the comments are gernan and therefore a little bit tricky.

yes, harmlos() works fine.
tödlich() does not work without yield, checked this already.

the Animated Sprite is addressed correct. Everything (FlintWalk, FlintJump, Flint_Idle) plays very well.

can it be the signal? for harmlos() the signal works perfect. toedlich() ist almost the same thing but for a different enemie and with another animation....

0 votes

(sorry, i misread your original post and i thought it was an animation player node in my previous comment)

most likely spriteFlint.play("Dummgelaufen") get blocked by the below line of code (maybe a random mouse movement?), that revert the play to idle inside checkkey_input():

if movement.x == 0 && movement.y == 0 && is_on_floor() && is_alive == true:
    spriteFlint.play("Flint_Idle")

if this was not the reason, you need to do some debuggin:
are you sure toedlich() is actually called?
are you sure spriteFlint actually points to the correct animated sprite node?
does harmlos() works correctly?
does it works without yield?

by (1,455 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.