Class: Nimo::Animation
- Defined in:
- lib/nimo/representations/sprite_representation.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #frame_index ⇒ Object
-
#initialize(name, frame_indexes, options) ⇒ Animation
constructor
A new instance of Animation.
- #reset_animation ⇒ Object
Constructor Details
#initialize(name, frame_indexes, options) ⇒ Animation
Returns a new instance of Animation.
55 56 57 58 59 60 |
# File 'lib/nimo/representations/sprite_representation.rb', line 55 def initialize(name, frame_indexes, ) @name = name @frame_indexes = frame_indexes @options = {:timeout => 0.1, :loop => true}.merge() reset_animation end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
53 54 55 |
# File 'lib/nimo/representations/sprite_representation.rb', line 53 def name @name end |
Instance Method Details
#frame_index ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/nimo/representations/sprite_representation.rb', line 67 def frame_index if (Time.now - @time_since_last_draw) > @options[:timeout] @time_since_last_draw = Time.now @current_index += 1 if @current_index == @frame_indexes.size @current_index = @options[:loop] ? 0 : @frame_indexes.size - 1 end end @frame_indexes[@current_index] end |
#reset_animation ⇒ Object
62 63 64 65 |
# File 'lib/nimo/representations/sprite_representation.rb', line 62 def reset_animation @current_index = 0 @time_since_last_draw = Time.now end |