Class: Ray::Animation::FloatVariation
- Inherits:
-
Ray::Animation
- Object
- Ray::Animation
- Ray::Animation::FloatVariation
- Defined in:
- lib/ray/animation/float_variation.rb
Overview
Animates the transition of a float to another one. Registered as #float_variation.
Instance Attribute Summary collapse
-
#attribute ⇒ Symbol
readonly
Attribute modified by the animation.
-
#initial_value ⇒ Float
readonly
Initial value.
-
#variation ⇒ Float
readonly
Variation between the initial value and the last value.
Attributes inherited from Ray::Animation
Instance Method Summary collapse
-
#-@ ⇒ FloatVariation
The opposite variation.
- #end_animation ⇒ Object
- #setup(opts) ⇒ Object
- #setup_target ⇒ Object
- #update_target ⇒ Object
Methods inherited from Ray::Animation
#+, #-, #bounce!, #initialize, #loop!, #pause, #pause_animation, #paused?, #progression, register_for, #resume, #resume_animation, #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 ⇒ Symbol (readonly)
Returns Attribute modified by the animation.
59 60 61 |
# File 'lib/ray/animation/float_variation.rb', line 59 def attribute @attribute end |
#initial_value ⇒ Float (readonly)
Returns Initial value.
62 63 64 |
# File 'lib/ray/animation/float_variation.rb', line 62 def initial_value @initial_value end |
#variation ⇒ Float (readonly)
Returns Variation between the initial value and the last value.
65 66 67 |
# File 'lib/ray/animation/float_variation.rb', line 65 def variation @variation end |
Instance Method Details
#-@ ⇒ FloatVariation
Returns The opposite variation.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ray/animation/float_variation.rb', line 46 def -@ if @initial_value float_variation(:from => @initial_value + @variation, :to => @initial_value, :attribute => @attribute, :duration => duration) else float_variation(:of => -@variation, :attribute => @attribute, :duration => duration) end end |
#end_animation ⇒ Object
41 42 43 |
# File 'lib/ray/animation/float_variation.rb', line 41 def end_animation target.send("#{@attribute}=", @current_value + @variation) end |
#setup(opts) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ray/animation/float_variation.rb', line 14 def setup(opts) if opts[:of] @initial_value = nil @variation = opts[:of] else @initial_value = opts[:from] @variation = opts[:to] - @initial_value end @attribute = opts[:attribute] self.duration = opts[:duration] end |
#setup_target ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ray/animation/float_variation.rb', line 28 def setup_target unless @initial_value @current_value = target.send(@attribute) else @current_value = @initial_value end end |
#update_target ⇒ Object
36 37 38 39 |
# File 'lib/ray/animation/float_variation.rb', line 36 def update_target increase = progression * @variation target.send("#{@attribute}=", @current_value + increase) end |