class Sprite
class Sprite
Attributes
done[W]
pause[W]
repeat[W]
Public Class Methods
new(symbol, repeat = false, frame_delay = 400, lifecycle = false)
click to toggle source
# File lib/misc/sprite.rb, line 14 def initialize(symbol, repeat = false, frame_delay = 400, lifecycle = false) @frame_delay = frame_delay @animation = $window.mediamanager.get_sprites(symbol) @animate = @animation.kind_of?(Array) @current_frame = 0 @repeat = repeat @lifecycle = lifecycle @pause = false end
Public Instance Methods
done?()
click to toggle source
# File lib/misc/sprite.rb, line 36 def done? return false if !@animate || @repeat @done ||= @current_frame == @animation.size - 1 if @lifecycle end
draw(x, y, layout)
click to toggle source
# File lib/misc/sprite.rb, line 30 def draw(x, y, layout) return if done? image = current_frame image.draw(x, y, layout, 1, 1) end
update()
click to toggle source
# File lib/misc/sprite.rb, line 24 def update return unless @animate return if @pause @current_frame = (@current_frame + 1) % @animation.size if frame_expired? end
Private Instance Methods
current_frame()
click to toggle source
# File lib/misc/sprite.rb, line 43 def current_frame return @animation unless @animate @animation[@current_frame % @animation.size] end
frame_expired?()
click to toggle source
# File lib/misc/sprite.rb, line 48 def frame_expired? now = Gosu.milliseconds @last_frame ||= now @last_frame = now if (now - @last_frame) > @frame_delay end