Class: MovieMaker::Action::Zoom

Inherits:
SpriteAction show all
Defined in:
lib/movie_maker/action.rb

Overview

Zoom a sprite

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 = {}, factor = 1) ⇒ Zoom

Returns a new instance of Zoom.



164
165
166
167
# File 'lib/movie_maker/action.rb', line 164

def initialize(options = {}, factor = 1)
	super(options)
	@factor = factor
end

Instance Method Details

#finalizeObject



188
189
190
191
192
# File 'lib/movie_maker/action.rb', line 188

def finalize
	@sprite.width_scaling = @factor
	@sprite.height_scaling = @factor
	@finalized = true
end

#setupObject



169
170
171
172
173
174
175
176
177
# File 'lib/movie_maker/action.rb', line 169

def setup
	@scale_from = @sprite.width_scaling || 1
	@scale = (@scale_from - @factor).abs

	@scale_step = @scale.to_f / @duration.to_f
	@scale_step = -@scale_step 	if	@factor < @scale_from
		
	@setup_done = true
end

#update(time) ⇒ Object



179
180
181
182
183
184
185
186
# File 'lib/movie_maker/action.rb', line 179

def update(time)
	setup	unless @setup_done
	
	scale = @scale_from + @scale_step * time
	#puts "#{scale} = #{@scale_from} + #{@scale_step} * #{time}"
	@sprite.width_scaling = scale
	@sprite.height_scaling = scale
end