Class: Ray::Animation::Sequence

Inherits:
Ray::Animation show all
Defined in:
lib/ray/animation/sequence.rb

Overview

Stores an array of animations that will be executed sequentially.

Registered as animation_sequence.

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

#animationsArray<Ray::Animation> (readonly)

Returns:



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

def animations
  @animations
end

Instance Method Details

#-@Ray::Animation::Sequence

Returns Animation sequence, calling reversed animations in reversed order.

Returns:



56
57
58
59
# File 'lib/ray/animation/sequence.rb', line 56

def -@
  anims = @animations.reverse.map { |anim| -anim }
  animation_sequence(*anims)
end

#pause_animationObject



36
37
38
# File 'lib/ray/animation/sequence.rb', line 36

def pause_animation
  @current_anim.pause
end

#push(*animations) ⇒ Object Also known as: <<

Adds several animations to the sequence.



45
46
47
48
49
50
# File 'lib/ray/animation/sequence.rb', line 45

def push(*animations)
  @animations.concat(animations)
  self.duration += animations.inject(0) { |sum, a| sum + a.duration }

  self
end

#resume_animationObject



40
41
42
# File 'lib/ray/animation/sequence.rb', line 40

def resume_animation
  @current_anim.resume
end

#setup(*animations) ⇒ Object

Parameters:



10
11
12
13
14
15
# File 'lib/ray/animation/sequence.rb', line 10

def setup(*animations)
  @animations   = animations
  @current_anim = nil

  self.duration = @animations.inject(0) { |sum, a| sum + a.duration }
end

#setup_targetObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ray/animation/sequence.rb', line 17

def setup_target
  @animations.each { |anim| anim.event_runner = event_runner }

  @animations.each_cons(2) do |prev, succ|
    on :animation_end, prev do
      @current_anim = succ
      succ.start target
    end
  end

  @current_anim = @animations.first

  @current_anim.start target
end

#update_targetObject



32
33
34
# File 'lib/ray/animation/sequence.rb', line 32

def update_target
  @current_anim.update
end