Class: Ray::Animation::VectorVariation
- Inherits:
-
Ray::Animation
- Object
- Ray::Animation
- Ray::Animation::VectorVariation
- Defined in:
- lib/ray/animation/vector_variation.rb
Overview
Animates the transition from a vector to another one. Registered as #vector_variation.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#current_value ⇒ Object
Returns the value of attribute current_value.
-
#initial_value ⇒ Object
readonly
Returns the value of attribute initial_value.
-
#variation ⇒ Object
readonly
Returns the value of attribute variation.
Attributes inherited from Ray::Animation
Instance Method Summary collapse
-
#-@ ⇒ VectorVariation
The opposite vector variation.
- #last_value ⇒ Object
- #pause_animation ⇒ Object
- #resume_animation ⇒ Object
- #setup(opts) ⇒ 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
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
92 93 94 |
# File 'lib/ray/animation/vector_variation.rb', line 92 def attribute @attribute end |
#current_value ⇒ Object
Returns the value of attribute current_value.
88 89 90 |
# File 'lib/ray/animation/vector_variation.rb', line 88 def current_value @current_value end |
#initial_value ⇒ Object (readonly)
Returns the value of attribute initial_value.
90 91 92 |
# File 'lib/ray/animation/vector_variation.rb', line 90 def initial_value @initial_value end |
#variation ⇒ Object (readonly)
Returns the value of attribute variation.
91 92 93 |
# File 'lib/ray/animation/vector_variation.rb', line 91 def variation @variation end |
Instance Method Details
#-@ ⇒ VectorVariation
Returns The opposite vector variation.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ray/animation/vector_variation.rb', line 76 def -@ if @initial_value vector_variation(:to => @initial_value.dup, :from => @initial_value + @variation, :attribute => @attribute, :duration => duration) else vector_variation(:of => -@variation, :attribute => @attribute, :duration => duration) end end |
#last_value ⇒ Object
94 95 96 |
# File 'lib/ray/animation/vector_variation.rb', line 94 def last_value @initial_value + @variation if @initial_value end |
#pause_animation ⇒ Object
62 63 64 |
# File 'lib/ray/animation/vector_variation.rb', line 62 def pause_animation @animations.each { |anim| anim.pause } end |
#resume_animation ⇒ Object
66 67 68 |
# File 'lib/ray/animation/vector_variation.rb', line 66 def resume_animation @animations.each { |anim| anim.resume } end |
#setup(opts) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ray/animation/vector_variation.rb', line 14 def setup(opts) if opts[:of] @current_value = @initial_value = nil @variation = opts[:of] if (@variation.is_a?(Array) && @variation.size == 3) || @variation.is_a?(Ray::Vector3) @variation = @variation.to_vector3 else @variation = @variation.to_vector2 end else if (opts[:from].is_a?(Array) && opts[:from].size == 2) || opts[:from].is_a?(Ray::Vector2) @initial_value = opts[:from].to_vector2 @variation = opts[:to].to_vector2 - @initial_value else @initial_value = opts[:from].to_vector3 @variation = opts[:to].to_vector3 - @initial_value end end @attribute = opts[:attribute] self.duration = opts[:duration] end |
#setup_target ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ray/animation/vector_variation.rb', line 41 def setup_target unless @initial_value @current_value = target.send(@attribute) else @current_value = @initial_value.dup end @animations = [] @animations << float_variation(:of => @variation.x, :attribute => :x, :duration => duration) @animations << float_variation(:of => @variation.y, :attribute => :y, :duration => duration) if @variation.is_a? Ray::Vector3 @animations << float_variation(:of => @variation.z, :attribute => :z, :duration => duration) end @animations.each { |anim| anim.start(@current_value) } end |
#update_target ⇒ Object
70 71 72 73 |
# File 'lib/ray/animation/vector_variation.rb', line 70 def update_target @animations.each { |anim| anim.update } target.send("#{@attribute}=", @current_value) end |