Class: Ray::Animation::Combination

Inherits:
Ray::Animation show all
Defined in:
lib/ray/animation/combination.rb

Overview

This class allows to use a single object to apply several kind of animations to a same target.

Note combining two animations affecting the same attribute usually won’t work.

Thus:

translation(:of => [10, 10], :duration => 2) +
  translation(:of => [10, 10], :duration => 2)

Is not the same as:

translation(:of => [20, 20], :duration => 2)

Instance Attribute Summary collapse

Attributes inherited from Ray::Animation

#duration, #end_time, #target

Instance Method Summary collapse

Methods inherited from Ray::Animation

#bounce!, #end_animation, #initialize, #loop!, #pause, #paused?, #progression, register_for, #resume, #running?, #start, #update

Methods included from Helper

#create_event_runner, #disable_event_group, effect_generator, #enable_event_group, #event_runner, #event_runner=, font, holding?, image, image_target, mouse_pos, music, #remove_event_group, #rotation, #scale_variation, sound, sound_buffer, sprite, text, #translation

Methods included from Matchers

key, key_mod, where

Methods included from DSL::EventListener

#add_hook, #current_event_group, #current_event_group=, #event_group, #listener_runner, #listener_runner=, #on

Methods included from DSL::EventRaiser

#raise_event, #raiser_runner, #raiser_runner=

Constructor Details

This class inherits a constructor from Ray::Animation

Instance Attribute Details

#animationsArray<Ray::Animation> (readonly)

Returns:



68
69
70
# File 'lib/ray/animation/combination.rb', line 68

def animations
  @animations
end

Instance Method Details

#+(animation) ⇒ Ray::Animation::Combination

Returns Combination of self and the argument.

Returns:



52
53
54
# File 'lib/ray/animation/combination.rb', line 52

def +(animation)
  animation_combination(*(@animations + [animation]))
end

#-(animation) ⇒ Ray::Animation::Combination

Returns Combination of self and the oppsite of the argument.

Returns:



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

def -(animation)
  animation_combination(*(@animations + [-animation]))
end

#-@Ray::Animation::Combination

Returns Combination of the opposite of each animation stored in this object.

Returns:



63
64
65
# File 'lib/ray/animation/combination.rb', line 63

def -@
  animation_combination(*@animations.map { |anim| -anim })
end

#pause_animationObject



32
33
34
# File 'lib/ray/animation/combination.rb', line 32

def pause_animation
  @animations.each { |anim| anim.pause }
end

#push(*animations) ⇒ Object Also known as: <<

Adds several animations to this combination.



41
42
43
44
45
46
47
# File 'lib/ray/animation/combination.rb', line 41

def push(*animations)
  @animations.concat(animations)
  max_duration = animations.map(&:duration).max || 0
  self.duration = max_duration if max_duration > duration

  self
end

#resume_animationObject



36
37
38
# File 'lib/ray/animation/combination.rb', line 36

def resume_animation
  @animations.each { |anim| anim.resume }
end

#setup(*args) ⇒ Object



19
20
21
22
# File 'lib/ray/animation/combination.rb', line 19

def setup(*args)
  @animations = args
  self.duration = @animations.map(&:duration).max || 0
end

#setup_targetObject



24
25
26
# File 'lib/ray/animation/combination.rb', line 24

def setup_target
  @animations.each { |anim| anim.start(target) }
end

#update_targetObject



28
29
30
# File 'lib/ray/animation/combination.rb', line 28

def update_target
  @animations.each { |anim| anim.update }
end