-# Special `Sprite` for the player character which is animated
-class PlayerSprite
- super Sprite
-
- # Animation of the running character
- var running_animation: Array[Texture]
-
- # Seconds per frame of the animations
- var time_per_frame: Float
-
- # Currently playing animation
- private var current_animation: nullable Array[Texture] = null
-
- # Second at witch `current_animation` started
- private var anim_ot = 0.0
-
- # Start the running animation
- fun start_running
- do
- anim_ot = app.world.t
- current_animation = running_animation
- end
-
- # Stop the running animation
- fun stop_running do current_animation = null
-
- redef fun texture
- do
- var anim = current_animation
- if anim != null then
- var dt = app.world.t - anim_ot
- var i = (dt / time_per_frame).to_i+2
- return anim.modulo(i)
- end
-
- return super
- end
-end
-