# About character animation state switching

**URL:** <https://forum.defold.com/t/about-character-animation-state-switching/75155>\
**Category:** Questions\
**Created:** [November 30, 2023, 8:57am UTC](https://forum.defold.com/t/about-character-animation-state-switching/75155 "2023-11-30T08:57:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HinamiAoi](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/hinamiaoi/32/34173_2.png) [@HinamiAoi](https://forum.defold.com/u/HinamiAoi)\
**Post date:** [November 30, 2023, 8:57am UTC](https://forum.defold.com/t/about-character-animation-state-switching/75155/1 "2023-11-30T08:57:55Z")

</div>

```
	if action_id == hash("up") then
		position.y = position.y + 1
		if action.pressed then
			sprite.play_flipbook("#player", "up", function() os.exit() end)
		elseif action.released then
			sprite.play_flipbook("#player", "idle-up", function() os.exit() end)
		end

```

I’m using this judgment for playback now and it works but it’s not elegant, is there another way?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [November 30, 2023, 1:31pm UTC](https://forum.defold.com/t/about-character-animation-state-switching/75155/2 "2023-11-30T13:31:47Z")

</div>

Switching the animation based on input state is totally acceptable. One thing though is how you update the position. You should update the position in `update()` and apply the delta time to ensure frame rate independent movement. Like in this example: [Move forward](https://defold.com/examples/movement/move_forward/)

---

<div class="post-metadata">

**Author:** ![HinamiAoi](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/hinamiaoi/32/34173_2.png) [@HinamiAoi](https://forum.defold.com/u/HinamiAoi)\
**Post date:** [December 1, 2023, 2:54am UTC](https://forum.defold.com/t/about-character-animation-state-switching/75155/3 "2023-12-01T02:54:31Z")

</div>

thx man
