Class: Chobo::Animation
- Inherits:
-
Object
- Object
- Chobo::Animation
- Defined in:
- lib/chobo/animation.rb
Instance Attribute Summary collapse
-
#frames ⇒ Object
Returns the value of attribute frames.
-
#interval ⇒ Object
Returns the value of attribute interval.
Instance Method Summary collapse
- #frame ⇒ Object
-
#initialize(frames, interval, looping = true) ⇒ Animation
constructor
A new instance of Animation.
- #reset ⇒ Object
- #update(dt) ⇒ Object
Constructor Details
#initialize(frames, interval, looping = true) ⇒ Animation
Returns a new instance of Animation.
6 7 8 9 10 11 12 |
# File 'lib/chobo/animation.rb', line 6 def initialize frames, interval, looping = true @frames = frames @interval = interval @looping = looping @state = :running reset() end |
Instance Attribute Details
#frames ⇒ Object
Returns the value of attribute frames.
4 5 6 |
# File 'lib/chobo/animation.rb', line 4 def frames @frames end |
#interval ⇒ Object
Returns the value of attribute interval.
4 5 6 |
# File 'lib/chobo/animation.rb', line 4 def interval @interval end |
Instance Method Details
#frame ⇒ Object
36 37 38 |
# File 'lib/chobo/animation.rb', line 36 def frame @frames[@current_frame] end |
#reset ⇒ Object
14 15 16 17 18 |
# File 'lib/chobo/animation.rb', line 14 def reset @current = 0.0 @current_frame = 0 @state = :running end |
#update(dt) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chobo/animation.rb', line 20 def update dt if @state == :running @current += dt if @current > @interval @current_frame += 1 if @current_frame > @frames.size - 1 if @looping reset() else @state = :stopped end end end end end |