Class: Ruby2D::Sprite
- Inherits:
-
Object
- Object
- Ruby2D::Sprite
- Defined in:
- lib/ruby2d/sprite.rb,
ext/ruby2d/ruby2d-opal.rb
Instance Attribute Summary collapse
-
#clip_h ⇒ Object
Returns the value of attribute clip_h.
-
#clip_w ⇒ Object
Returns the value of attribute clip_w.
-
#clip_x ⇒ Object
Returns the value of attribute clip_x.
-
#clip_y ⇒ Object
Returns the value of attribute clip_y.
-
#data ⇒ Object
Returns the value of attribute data.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #add(animations) ⇒ Object
- #animate(animation) ⇒ Object
- #init(path) ⇒ Object
-
#initialize(x, y, path) ⇒ Sprite
constructor
A new instance of Sprite.
-
#remove ⇒ Object
TODO: Sprite already has an ‘add` method, have to reconsile def add if Module.const_defined? :DSL Application.add(self) end end.
- #reset ⇒ Object
- #start(x, y, w, h) ⇒ Object
Constructor Details
#initialize(x, y, path) ⇒ Sprite
Returns a new instance of Sprite.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby2d/sprite.rb', line 8 def initialize(x, y, path) # unless File.exists? path # raise Error, "Cannot find image file `#{path}`" # end @type_id = 4 @x, @y, @path = x, y, path @clip_x, @clip_y, @clip_w, @clip_h = 0, 0, 0, 0 @default = nil @animations = {} @current_animation = nil @current_frame = 0 @current_frame_time = 0 init(path) if Module.const_defined? :DSL Application.add(self) end end |
Instance Attribute Details
#clip_h ⇒ Object
Returns the value of attribute clip_h.
6 7 8 |
# File 'lib/ruby2d/sprite.rb', line 6 def clip_h @clip_h end |
#clip_w ⇒ Object
Returns the value of attribute clip_w.
6 7 8 |
# File 'lib/ruby2d/sprite.rb', line 6 def clip_w @clip_w end |
#clip_x ⇒ Object
Returns the value of attribute clip_x.
6 7 8 |
# File 'lib/ruby2d/sprite.rb', line 6 def clip_x @clip_x end |
#clip_y ⇒ Object
Returns the value of attribute clip_y.
6 7 8 |
# File 'lib/ruby2d/sprite.rb', line 6 def clip_y @clip_y end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/ruby2d/sprite.rb', line 6 def data @data end |
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/ruby2d/sprite.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/ruby2d/sprite.rb', line 6 def y @y end |
Instance Method Details
#add(animations) ⇒ Object
34 35 36 |
# File 'lib/ruby2d/sprite.rb', line 34 def add(animations) @animations.merge!(animations) end |
#animate(animation) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/ruby2d/sprite.rb', line 38 def animate(animation) if @current_animation != animation @current_frame = 0 @current_frame_time = 0 @current_animation = animation end animate_frames(@animations[animation]) end |
#init(path) ⇒ Object
141 142 143 |
# File 'ext/ruby2d/ruby2d-opal.rb', line 141 def init(path) `#{self}.data = S2D.CreateSprite(path);` end |
#remove ⇒ Object
TODO: Sprite already has an ‘add` method, have to reconsile def add
if Module.const_defined? :DSL
Application.add(self)
end
end
59 60 61 62 63 |
# File 'lib/ruby2d/sprite.rb', line 59 def remove if Module.const_defined? :DSL Application.remove(self) end end |
#reset ⇒ Object
47 48 49 50 |
# File 'lib/ruby2d/sprite.rb', line 47 def reset clip(@default[0], @default[1], @default[2], @default[3]) @current_animation = nil end |
#start(x, y, w, h) ⇒ Object
29 30 31 32 |
# File 'lib/ruby2d/sprite.rb', line 29 def start(x, y, w, h) @default = [x, y, w, h] clip(x, y, w, h) end |