Class: Ray::AnimationList

Inherits:
Object
  • Object
show all
Includes:
Enumerable, PP
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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from PP

#pretty_print_attributes

Constructor Details

#initializeAnimationList

Returns a new instance of AnimationList.



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

def initialize
  @animations = []
end

Instance Attribute Details

#animationsArray<Ray::Animation> (readonly) Also known as: to_a

Returns:



53
54
55
# File 'lib/ray/animation_list.rb', line 53

def animations
  @animations
end

Instance Method Details

#<<(elem) ⇒ Object

Parameters:

  • elem (Ray::Animation)

    An animation to add to the animation list.



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

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

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

Yields:

  • Iterates over all of the animations.

Yield Parameters:



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

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



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

def empty?
  @animations.empty?
end

#inspectObject



57
58
59
# File 'lib/ray/animation_list.rb', line 57

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

#pretty_print(q) ⇒ Object



61
62
63
# File 'lib/ray/animation_list.rb', line 61

def pretty_print(q)
  pretty_print_attributes q, ["animations"]
end

#remove_unusedObject

Removes animations that are no more in use



37
38
39
40
41
42
43
# File 'lib/ray/animation_list.rb', line 37

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

  self
end

#updateObject

Updates all the animations



31
32
33
34
# File 'lib/ray/animation_list.rb', line 31

def update
  @animations.each(&:update)
  self
end