Class: Ray::AnimationList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ray/animation_list.rb

Overview

Animations lists are collections of animations, updating them and removing all the animations that are done running. As this the only thing you’ll need to do most of the time, you can just push an animation at the end of it and let Scene do the rest of the work.

Examples:

animations << color_variation(:from => [255, 0, 0], :to => [0, 255, 0],
                              :duration => 3).start(sprite)

Instance Method Summary collapse

Constructor Details

#initializeAnimationList

Returns a new instance of AnimationList.



14
15
16
# File 'lib/ray/animation_list.rb', line 14

def initialize
  @animations = []
end

Instance Method Details

#<<(elem) ⇒ Object

Parameters:

  • elem (Ray::Animation)

    An animation to add to the animation list.



24
25
26
27
# File 'lib/ray/animation_list.rb', line 24

def <<(elem)
  @animations << elem
  self
end

#each {|anim| ... } ⇒ Object

Yields:

  • Iterates over all of the animations.

Yield Parameters:



41
42
43
44
# File 'lib/ray/animation_list.rb', line 41

def each(&block)
  @animations.each(&block)
  self
end

#empty?true, false

Returns True if the animation list is empty.

Returns:

  • (true, false)

    True if the animation list is empty



19
20
21
# File 'lib/ray/animation_list.rb', line 19

def empty?
  @animations.empty?
end

#inspectObject



46
47
48
# File 'lib/ray/animation_list.rb', line 46

def inspect
  "#{self.class}#{@animations.inspect}"
end

#updateObject

Updates all the animations, and removes those that are finished.



30
31
32
33
34
35
36
37
# File 'lib/ray/animation_list.rb', line 30

def update
  @animations.reject! do |anim|
    anim.update
    !anim.running? && !anim.paused?
  end

  self
end