Class: RGame::Engine::Animator
- Inherits:
-
Object
- Object
- RGame::Engine::Animator
- Defined in:
- lib/rgame/engine/animator.rb
Overview
Owns animation playback state for one actor: the AnimationSet plus the current animation name and elapsed time. Pure logic — the renderer asks it for the current [row, col, flip_x] cell. This is what makes an actor own its own animations instead of the scene passing an AnimationSet in every frame.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#elapsed ⇒ Object
readonly
Returns the value of attribute elapsed.
Instance Method Summary collapse
- #col ⇒ Object
- #flip_x ⇒ Object
-
#frame ⇒ Object
[row, col, flip_x] for the current animation at the current elapsed time.
-
#initialize(animation_set, initial: :stand) ⇒ Animator
constructor
A new instance of Animator.
-
#play(name) ⇒ Object
Switch to
name; restarts elapsed time on an actual change (a no-op if the animation is already playing, so a continuing walk keeps cycling). -
#row ⇒ Object
Current animation's row/col/flip_x, resolved without allocating — the per-frame draw path reads these directly.
- #update(dt) ⇒ Object
Constructor Details
#initialize(animation_set, initial: :stand) ⇒ Animator
Returns a new instance of Animator.
10 11 12 13 14 |
# File 'lib/rgame/engine/animator.rb', line 10 def initialize(animation_set, initial: :stand) @animation_set = animation_set @current = initial @elapsed = 0.0 end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
16 17 18 |
# File 'lib/rgame/engine/animator.rb', line 16 def current @current end |
#elapsed ⇒ Object (readonly)
Returns the value of attribute elapsed.
16 17 18 |
# File 'lib/rgame/engine/animator.rb', line 16 def elapsed @elapsed end |
Instance Method Details
#col ⇒ Object
34 |
# File 'lib/rgame/engine/animator.rb', line 34 def col = @animation_set.col(@current, @elapsed) |
#flip_x ⇒ Object
35 |
# File 'lib/rgame/engine/animator.rb', line 35 def flip_x = @animation_set.flip_x(@current) |
#frame ⇒ Object
[row, col, flip_x] for the current animation at the current elapsed time. A convenience for tests/inspection; it allocates, so draw uses the accessors above.
39 40 41 |
# File 'lib/rgame/engine/animator.rb', line 39 def frame @animation_set.frame(@current, @elapsed) end |
#play(name) ⇒ Object
Switch to name; restarts elapsed time on an actual change (a no-op if the
animation is already playing, so a continuing walk keeps cycling).
20 21 22 23 24 25 |
# File 'lib/rgame/engine/animator.rb', line 20 def play(name) return if name == @current @current = name @elapsed = 0.0 end |
#row ⇒ Object
Current animation's row/col/flip_x, resolved without allocating — the per-frame draw path reads these directly.
33 |
# File 'lib/rgame/engine/animator.rb', line 33 def row = @animation_set.row(@current) |
#update(dt) ⇒ Object
27 28 29 |
# File 'lib/rgame/engine/animator.rb', line 27 def update(dt) @elapsed += dt end |