Class: RedBird::Animation::BackAndForth
- Defined in:
- lib/red_bird/animation.rb
Overview
This animation starts in the first frame and goes through every frame until the last; then, it moves backward through every frame and starts again.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#animate ⇒ Object
This method must be called for every tick.
Methods inherited from Base
Constructor Details
This class inherits a constructor from RedBird::Animation::Base
Instance Method Details
#animate ⇒ Object
This method must be called for every tick. It changes the current displayed sprite.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/red_bird/animation.rb', line 96 def animate case @direction when :forward @current_time += 1 if @current_time > @frames[@current_frame].duration then @current_time -= @frames[@current_frame].duration @current_frame += 1 if @current_frame >= @frames.size then @direction = :backward @current_frame = @frames.size - 2 end @current_sprite = @frames[@current_frame].sprite end when :backward @current_time += 1 if @current_time > @frames[@current_frame].duration then @current_time -= @frames[@current_frame].duration @current_frame -= 1 if @current_frame < 0 then @direction = :forward @current_frame = 1 end @current_sprite = @frames[@current_frame].sprite end end end |