Class: Ray::Animation::BlockAnimation

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

Overview

Animation occurring by running a block. Registered as #block_animation.

Examples:

block_animation :duration => 10, :block => proc { |target, progression|
  p target => progression
}

Instance Attribute Summary

Attributes inherited from Ray::Animation

#duration, #end_time, #target

Instance Method Summary collapse

Methods inherited from Ray::Animation

#+, #-, #bounce!, #end_animation, #initialize, #loop!, #pause, #pause_animation, #paused?, #progression, register_for, #resume, #resume_animation, #running?, #setup_target, #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 Method Details

#-@BlockAnimation

Returns Reversed animation.

Returns:



30
31
32
33
# File 'lib/ray/animation/block_animation.rb', line 30

def -@
  block_animation(:block => @block, :reversed => !@reversed,
                  :duration => @duration)
end

#setup(opts) ⇒ Object

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :block (#call)

    Object which will be called with the target and a progression between 0 and 1.

  • :proc (#call)

    Same as :block.

  • :reversed (true, false) — default: false

    True to make the progression decrease from 1 to 0.

  • :duration (Float)

    Duration in seconds.



18
19
20
21
22
23
# File 'lib/ray/animation/block_animation.rb', line 18

def setup(opts)
  @block    = opts[:block] || opts[:proc]
  @reversed = opts.key?(:reversed) ? opts[:reversed] : false

  self.duration = opts[:duration]
end

#update_targetObject



25
26
27
# File 'lib/ray/animation/block_animation.rb', line 25

def update_target
  @block.call(target, @reversed ? 1 - progression : progression)
end