Class: MovieMaker::Action::Move
- Inherits:
-
SpriteAction
- Object
- SpriteAction
- MovieMaker::Action::Move
- Defined in:
- lib/movie_maker/action.rb
Overview
Moves a sprite to a set of coordinates
Instance Attribute Summary
Attributes inherited from SpriteAction
#background, #image, #screen, #sprite, #start_at, #stop_at
Instance Method Summary collapse
- #finalize ⇒ Object
-
#initialize(options = {}, coordinates = [0,0]) ⇒ Move
constructor
A new instance of Move.
- #setup ⇒ Object
-
#update(time) ⇒ Object
The core of the MoveClass, the actual move-logic.
Methods inherited from SpriteAction
#finalized?, #playing?, #started?
Constructor Details
#initialize(options = {}, coordinates = [0,0]) ⇒ Move
Returns a new instance of Move.
63 64 65 66 67 68 |
# File 'lib/movie_maker/action.rb', line 63 def initialize( = {}, coordinates = [0,0]) super() @to_x = coordinates[0] @to_y = coordinates[1] @prev_time = 0 end |
Instance Method Details
#finalize ⇒ Object
89 90 91 92 93 |
# File 'lib/movie_maker/action.rb', line 89 def finalize @sprite.x = @to_x @sprite.y = @to_y @finalized = true end |
#setup ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/movie_maker/action.rb', line 70 def setup @from_x = @sprite.x @from_y = @sprite.y @x_step = (@to_x - @from_x).to_f / @duration.to_f @y_step = (@to_y - @from_y).to_f / @duration.to_f @setup_done = true end |
#update(time) ⇒ Object
The core of the MoveClass, the actual move-logic
79 80 81 82 83 84 85 86 87 |
# File 'lib/movie_maker/action.rb', line 79 def update(time) setup unless @setup_done @diff = (time - @prev_time) @prev_time = time @sprite.x += @diff * @x_step.to_f @sprite.y += @diff * @y_step.to_f end |