Class: Ray::Animation::VectorVariation

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

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

#attributeObject (readonly)

Returns the value of attribute attribute.



92
93
94
# File 'lib/ray/animation/vector_variation.rb', line 92

def attribute
  @attribute
end

#current_valueObject

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_valueObject (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

#variationObject (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.

Returns:



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_valueObject



94
95
96
# File 'lib/ray/animation/vector_variation.rb', line 94

def last_value
  @initial_value + @variation if @initial_value
end

#pause_animationObject



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

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

#resume_animationObject



66
67
68
# File 'lib/ray/animation/vector_variation.rb', line 66

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

#setup(opts) ⇒ Object

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):



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_targetObject



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_targetObject



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