+1 vote

I want to create a breakable block. I create an animated sprite in which it has 4 frames that represent the block state. How do I set the frame of the animated sprite manually?
it seems like $AnimatedSprite.frame = 0 is not working.

EDIT: Here's my script:

extends StaticBody2D
var Life = 100
func _physics_process(delta):
         match Life:
                 $AnimatedSprite.frame = 0
                 $AnimatedSprite.frame = 1
                 $AnimatedSprite.frame = 2
                 $AnimatedSprite.frame = 3
                 $AnimatedSprite.frame = 4

As I debug it, the match statement stays in the first expression even if the life is not 100.
I guess that this is not how the match function is used, either way, can anyone know how to implement this?

EDIT: I food the problem. The problem is that the match function needs to be accurate literally. But my damage is 6 so it makes sense that it doesn't hit those match statement.

What I need now is to add ">" in the match function but I don't know how

EDIT: F... this match function, what I do is normal if's and it solved the problem

if Life >= 100:
    $AnimatedSprite.frame = 0
elif Life >= 75:
    $AnimatedSprite.frame = 1
elif Life >= 50:
    $AnimatedSprite.frame = 2
elif Life >= 25:
    $AnimatedSprite.frame = 3
elif Life >=0:
    $AnimatedSprite.frame = 4
Godot version 3.2.3
in Engine by (378 points)
edited by
$AnimatedSprite.frame = int(4 - floor(Life / 25.0))
if Life <= 0: queue_free()

This should also work and looks a bit nicer. And should also run faster.
Just my opinion.

Please log in or register to answer this question.

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.