Class: Ray::Animation::FloatVariation

Inherits:
Ray::Animation show all
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

Attributes inherited from Ray::Animation

#duration, #end_time, #target

Instance Method Summary collapse

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

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

#attributeSymbol (readonly)

Returns Attribute modified by the animation.

Returns:

  • (Symbol)

    Attribute modified by the animation.



59
60
61
# File 'lib/ray/animation/float_variation.rb', line 59

def attribute
  @attribute
end

#initial_valueFloat (readonly)

Returns Initial value.

Returns:

  • (Float)

    Initial value.



62
63
64
# File 'lib/ray/animation/float_variation.rb', line 62

def initial_value
  @initial_value
end

#variationFloat (readonly)

Returns Variation between the initial value and the last value.

Returns:

  • (Float)

    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.

Returns:



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_animationObject



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

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :of (Float)

    Variation of the value. May be negative. Required unless :to and :from are set.

  • :from (Float)

    Initial value of attribute.

  • :to (Float)

    Last value of attribute.

  • :attribute (Symbol)

    Attribute of the target to change.

  • :duration (Float)

    Duration in seconds.



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_targetObject



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_targetObject



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