0 votes

when i use 4 direction code i can i apply my idle/facing by switch string like this:

    if move_direction.y == 0:
        move_direction.x = int(RIGHT) -int(LEFT)
    if move_direction.x == 0:
        move_direction.y = int(DOWN)  -int(UP)

    if move_direction != dir.center:
        animation_play("Fmove")
    else:
        animation_play("Fidle")



func sprite_loop():
    match move_direction:
        dir.right:
            sprite_direction = "_Right"
        dir.left:
            sprite_direction = "_Left"
        dir.up:
            sprite_direction = "_Up"
        dir.down:
            sprite_direction = "_Down"


func animation_play(animation):# to atcive animation_switch
    var New_anim = str(animation,sprite_direction)
    if $anim.current_animation != New_anim:
        $anim.play(New_anim)

but when use 8 direction, i dont know how to switch to my idle/facing direction.

func animation_switch():
var RIGHT = Input.is_action_pressed("ui_right")
var LEFT = Input.is_action_pressed("ui_left")
var DOWN = Input.is_action_pressed("ui_down")
var UP = Input.is_action_pressed("ui_up")


move_direction.x = int(RIGHT) -int(LEFT)
move_direction.y = int(DOWN)  -int(UP)



if RIGHT and  !DOWN and !UP:
    animation_play("Fmove_Right")
elif LEFT and  !DOWN and !UP:
    animation_play("Fmove_Left")


if UP:
    if RIGHT:
         animation_play("Fmove_Up_Right")
    elif LEFT:
        animation_play("Fmove_Up_Left")
    else:
        animation_play("Fmove_Up")

if DOWN:
    if RIGHT:
        animation_play("Fmove_Down_Right")
    elif LEFT:
        animation_play("Fmove_Down_Left")
    else:
        animation_play("Fmove_Down")


func animation_play(animation):# to atcive animation_switch
        if $anim.current_animation != animation:
        $anim.play(animation)
in Engine by (394 points)

I have written an example in your previous question which might solve this problem. This time I extended the match statement you previously used, with 4 extra conditions. You will only need to add these conditions and set the variables for upleft, upright, downleft and downright and your code should work like before, but without moonwalking.

thank you so much

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.