Class: Ray::Animation::Combination
- Inherits:
-
Ray::Animation
- Object
- Ray::Animation
- Ray::Animation::Combination
- 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
- #animations ⇒ Array<Ray::Animation> readonly
Attributes inherited from Ray::Animation
Instance Method Summary collapse
-
#+(animation) ⇒ Ray::Animation::Combination
Combination of self and the argument.
-
#-(animation) ⇒ Ray::Animation::Combination
Combination of self and the oppsite of the argument.
-
#-@ ⇒ Ray::Animation::Combination
Combination of the opposite of each animation stored in this object.
- #pause_animation ⇒ Object
-
#push(*animations) ⇒ Object
(also: #<<)
Adds several animations to this combination.
- #resume_animation ⇒ Object
- #setup(*args) ⇒ Object
- #setup_target ⇒ Object
- #update_target ⇒ Object
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
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
#animations ⇒ Array<Ray::Animation> (readonly)
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.
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.
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.
63 64 65 |
# File 'lib/ray/animation/combination.rb', line 63 def -@ animation_combination(*@animations.map { |anim| -anim }) end |
#pause_animation ⇒ Object
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_animation ⇒ Object
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_target ⇒ Object
24 25 26 |
# File 'lib/ray/animation/combination.rb', line 24 def setup_target @animations.each { |anim| anim.start(target) } end |
#update_target ⇒ Object
28 29 30 |
# File 'lib/ray/animation/combination.rb', line 28 def update_target @animations.each { |anim| anim.update } end |