Class: MovieMaker::Action::Move

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

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(options = {}, coordinates = [0,0])
	super(options)
	@to_x = coordinates[0]
	@to_y = coordinates[1]
	@prev_time = 0
end

Instance Method Details

#finalizeObject



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

#setupObject



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