Class: Hemi::Render::Sprite

Inherits:
Texture
  • Object
show all
Defined in:
lib/hemi/render/sprite.rb

Constant Summary collapse

ERR__IMAGE_NOT_FOUND =
"Image %s not found.".freeze

Constants inherited from Texture

Texture::ERR__INVALID_POSITION

Class Attribute Summary collapse

Attributes inherited from Texture

#texture

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Texture

[], purge!, register

Constructor Details

#initialize(name) ⇒ Sprite

Returns a new instance of Sprite.



7
8
9
10
11
12
# File 'lib/hemi/render/sprite.rb', line 7

def initialize(name)
  @texture = Hemi::Render::Window.renderer.load_texture("assets/img/#{name}.bmp")
  Sprite.register(name, self)
rescue SDL2::Error => _e
  raise ArgumentError, format(ERR__IMAGE_NOT_FOUND, font_path)
end

Class Attribute Details

.spritesObject (readonly)

Returns the value of attribute sprites.



19
20
21
# File 'lib/hemi/render/sprite.rb', line 19

def sprites
  @sprites
end

Class Method Details

.bucketObject



21
22
23
# File 'lib/hemi/render/sprite.rb', line 21

def bucket
  :sprites
end

Instance Method Details

#render(position: nil, size: nil) ⇒ Object



14
15
16
# File 'lib/hemi/render/sprite.rb', line 14

def render(position: nil, size: nil)
  Hemi::Render::Window.renderer.copy(texture, nil, rectangle(position: position, size: size))
end