Class: Ray::Animation::SpriteAnimation
- Inherits:
-
Ray::Animation
- Object
- Ray::Animation
- Ray::Animation::SpriteAnimation
- Defined in:
- lib/ray/animation/sprite_animation.rb
Overview
Sprite animations are used to animate a position change in a sprite sheet.
It is written so that each step of the animation (including the latest one) has the same duration.
Instance Attribute Summary collapse
-
#current_value ⇒ Object
readonly
Returns the value of attribute current_value.
-
#initial_value ⇒ Object
readonly
Returns the value of attribute initial_value.
-
#negative_x ⇒ Object
readonly
Returns the value of attribute negative_x.
-
#negative_y ⇒ Object
readonly
Returns the value of attribute negative_y.
-
#x_steps ⇒ Object
readonly
Returns the value of attribute x_steps.
-
#y_steps ⇒ Object
readonly
Returns the value of attribute y_steps.
Attributes inherited from Ray::Animation
Instance Method Summary collapse
- #-@ ⇒ Object
- #end_animation ⇒ Object
- #setup(opts) ⇒ Object
- #update_target ⇒ Object
- #variation(x, y) ⇒ Object
Methods inherited from Ray::Animation
#+, #-, #bounce!, #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
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
#current_value ⇒ Object (readonly)
Returns the value of attribute current_value.
61 62 63 |
# File 'lib/ray/animation/sprite_animation.rb', line 61 def current_value @current_value end |
#initial_value ⇒ Object (readonly)
Returns the value of attribute initial_value.
63 64 65 |
# File 'lib/ray/animation/sprite_animation.rb', line 63 def initial_value @initial_value end |
#negative_x ⇒ Object (readonly)
Returns the value of attribute negative_x.
65 66 67 |
# File 'lib/ray/animation/sprite_animation.rb', line 65 def negative_x @negative_x end |
#negative_y ⇒ Object (readonly)
Returns the value of attribute negative_y.
65 66 67 |
# File 'lib/ray/animation/sprite_animation.rb', line 65 def negative_y @negative_y end |
#x_steps ⇒ Object (readonly)
Returns the value of attribute x_steps.
64 65 66 |
# File 'lib/ray/animation/sprite_animation.rb', line 64 def x_steps @x_steps end |
#y_steps ⇒ Object (readonly)
Returns the value of attribute y_steps.
64 65 66 |
# File 'lib/ray/animation/sprite_animation.rb', line 64 def y_steps @y_steps end |
Instance Method Details
#-@ ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/ray/animation/sprite_animation.rb', line 52 def -@ last_value = @initial_value + variation(@x_steps - 1, @y_steps - 1) sprite_animation(:from => @initial_value, :to => last_value, :loop => @loop, :duration => @duration) end |
#end_animation ⇒ Object
44 45 46 |
# File 'lib/ray/animation/sprite_animation.rb', line 44 def end_animation target.sheet_pos = @initial_value if @loop end |
#setup(opts) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ray/animation/sprite_animation.rb', line 16 def setup(opts) self.duration = opts[:duration] @initial_value = opts[:from].to_vector2.dup delta = opts[:to].to_vector2 - opts[:from].to_vector2 @x_steps = delta.x.to_i.abs + 1 @y_steps = delta.y.to_i.abs + 1 @negative_x = delta.x < 0 @negative_y = delta.y < 0 @loop = opts[:loop] end |
#update_target ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ray/animation/sprite_animation.rb', line 32 def update_target progress = progression x_prog = (progress * @x_steps).floor y_prog = (progress * @y_steps).floor x_prog = @x_steps - 1 if x_prog == @x_steps y_prog = @y_steps - 1 if y_prog == @y_steps target.sheet_pos = @initial_value + variation(x_prog, y_prog) end |