how to apply idle/facing animatioPlayer?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

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)

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.

nooberdev | 2018-08-07 10:21

thank you so much

potatobanana | 2018-08-07 13:19