Class: Sprite

Inherits:
Object
  • Object
show all
Defined in:
lib/misc/sprite.rb

Overview

class Sprite

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute done to.



10
11
12
# File 'lib/misc/sprite.rb', line 10

def done=(value)
  @done = value
end

#pause=(value) ⇒ Object (writeonly)

Sets the attribute pause

Parameters:

  • value

    the value to set the attribute pause to.



12
13
14
# File 'lib/misc/sprite.rb', line 12

def pause=(value)
  @pause = value
end

#repeat=(value) ⇒ Object (writeonly)

Sets the attribute repeat

Parameters:

  • value

    the value to set the attribute repeat to.



11
12
13
# File 'lib/misc/sprite.rb', line 11

def repeat=(value)
  @repeat = value
end

Instance Method Details

#done?Boolean

Returns:

  • (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

#updateObject



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