Class: Ruby2D::Tileset
- Inherits:
-
Object
- Object
- Ruby2D::Tileset
- Includes:
- Renderable
- Defined in:
- lib/ruby2d/tileset.rb
Instance Attribute Summary
Attributes included from Renderable
#color, #height, #width, #x, #y, #z
Instance Method Summary collapse
- #clear_tiles ⇒ Object
- #define_tile(name, x, y) ⇒ Object
-
#initialize(path, opts = {}) ⇒ Tileset
constructor
A new instance of Tileset.
- #set_tile(name, coordinates) ⇒ Object
Methods included from Renderable
#a, #a=, #add, #b, #b=, #contains?, #g, #g=, #opacity, #opacity=, #r, #r=, #remove
Constructor Details
#initialize(path, opts = {}) ⇒ Tileset
Returns a new instance of Tileset.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby2d/tileset.rb', line 7 def initialize(path, opts = {}) unless File.exist? path raise Error, "Cannot find tileset image file `#{path}`" end @path = path @tiles = [] @defined_tiles = {} @padding = opts[:padding] || 0 @spacing = opts[:spacing] || 0 @tile_width = opts[:tile_width] @tile_height = opts[:tile_height] unless ext_init(@path) raise Error, "Tileset `#{@path}` cannot be created" end unless opts[:show] == false then add end end |
Instance Method Details
#clear_tiles ⇒ Object
43 44 45 |
# File 'lib/ruby2d/tileset.rb', line 43 def clear_tiles @tiles = [] end |
#define_tile(name, x, y) ⇒ Object
26 27 28 |
# File 'lib/ruby2d/tileset.rb', line 26 def define_tile(name, x, y) @defined_tiles[name] = { x: x, y: y } end |
#set_tile(name, coordinates) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby2d/tileset.rb', line 30 def set_tile(name, coordinates) tile = @defined_tiles.fetch(name) coordinates.each do |coordinate| @tiles.push({ tile_x: tile.fetch(:x), tile_y: tile.fetch(:y), x: coordinate.fetch(:x), y: coordinate.fetch(:y) }) end end |