Class: Sprite
- Inherits:
-
Object
- Object
- Sprite
- Defined in:
- lib/misc/sprite.rb
Overview
class Sprite
Instance Attribute Summary collapse
-
#done ⇒ Object
writeonly
Sets the attribute done.
-
#pause ⇒ Object
writeonly
Sets the attribute pause.
-
#repeat ⇒ Object
writeonly
Sets the attribute repeat.
Instance Method Summary collapse
- #done? ⇒ Boolean
- #draw(x, y, layout) ⇒ Object
-
#initialize(symbol, repeat = false, frame_delay = 400, lifecycle = false) ⇒ Sprite
constructor
A new instance of Sprite.
- #update ⇒ Object
Constructor Details
#initialize(symbol, repeat = false, frame_delay = 400, lifecycle = false) ⇒ Sprite
Returns a new instance of Sprite.
14 15 16 17 18 19 20 21 22 |
# 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 |
Instance Attribute Details
#done=(value) ⇒ Object (writeonly)
Sets the attribute done
10 11 12 |
# File 'lib/misc/sprite.rb', line 10 def done=(value) @done = value end |
#pause=(value) ⇒ Object (writeonly)
Sets the attribute pause
12 13 14 |
# File 'lib/misc/sprite.rb', line 12 def pause=(value) @pause = value end |
#repeat=(value) ⇒ Object (writeonly)
Sets the attribute repeat
11 12 13 |
# File 'lib/misc/sprite.rb', line 11 def repeat=(value) @repeat = value end |
Instance Method Details
#done? ⇒ Boolean
36 37 38 39 |
# 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) ⇒ Object
30 31 32 33 34 |
# 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 ⇒ Object
24 25 26 27 28 |
# 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 |