Class: RedBird::TileSet
- Inherits:
-
Object
- Object
- RedBird::TileSet
- Defined in:
- lib/red_bird/tile_set.rb
Overview
Instance Attribute Summary collapse
-
#tile_height ⇒ Integer
readonly
Height of each tile.
-
#tile_width ⇒ Integer
readonly
Width of each tile.
- #tiles ⇒ Array<RedBird::TileSet::Sprite> readonly
Class Method Summary collapse
-
.from_yml(data_dir, tile_file, palette) ⇒ RedBird::TileSet
Load information from a yaml file and uses it create an instance of this class.
Instance Method Summary collapse
-
#initialize(texture_file, texture_palette, tile_width, tile_height) ⇒ TileSet
constructor
A new instance of TileSet.
Constructor Details
#initialize(texture_file, texture_palette, tile_width, tile_height) ⇒ TileSet
Returns a new instance of TileSet.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/red_bird/tile_set.rb', line 24 def initialize(texture_file, texture_palette, tile_width, tile_height) @texture = RedBird::Texture.new(texture_file, texture_palette) @tile_width = tile_width @tile_height = tile_height horizontal_tiles = @texture.width / @tile_width vertical_tiles = @texture.height / @tile_height @tiles = Sprite.grid( @texture, 0, 0, horizontal_tiles, vertical_tiles, @tile_width, @tile_height) end |
Instance Attribute Details
#tile_height ⇒ Integer (readonly)
Returns height of each tile.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/red_bird/tile_set.rb', line 16 class TileSet attr_reader :tiles, :tile_width, :tile_height # @param texture_file [String] this method uses the path as argument to # create a {RedBird::Texture}. # @param tile_width [Integer] width of each tile. # @param tile_height [Integer] height of each tile. # @author Frederico Linhares def initialize(texture_file, texture_palette, tile_width, tile_height) @texture = RedBird::Texture.new(texture_file, texture_palette) @tile_width = tile_width @tile_height = tile_height horizontal_tiles = @texture.width / @tile_width vertical_tiles = @texture.height / @tile_height @tiles = Sprite.grid( @texture, 0, 0, horizontal_tiles, vertical_tiles, @tile_width, @tile_height) end # Load information from a yaml file and uses it create an instance of this # class. # # @param data_dir [String] path to the directory containing the yaml and # other files referenced in the yaml. # @param tile_file [String] path to the yaml file. # @return [RedBird::TileSet] # @author Frederico Linhares def self.from_yml(data_dir, tile_file, palette) yaml_file = data_dir + tile_file data = YAML.load_file(yaml_file) texture_path = data_dir + data["texture"] return self.new(texture_path, palette, data["width"], data["height"]) end end |
#tile_width ⇒ Integer (readonly)
Returns width of each tile.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/red_bird/tile_set.rb', line 16 class TileSet attr_reader :tiles, :tile_width, :tile_height # @param texture_file [String] this method uses the path as argument to # create a {RedBird::Texture}. # @param tile_width [Integer] width of each tile. # @param tile_height [Integer] height of each tile. # @author Frederico Linhares def initialize(texture_file, texture_palette, tile_width, tile_height) @texture = RedBird::Texture.new(texture_file, texture_palette) @tile_width = tile_width @tile_height = tile_height horizontal_tiles = @texture.width / @tile_width vertical_tiles = @texture.height / @tile_height @tiles = Sprite.grid( @texture, 0, 0, horizontal_tiles, vertical_tiles, @tile_width, @tile_height) end # Load information from a yaml file and uses it create an instance of this # class. # # @param data_dir [String] path to the directory containing the yaml and # other files referenced in the yaml. # @param tile_file [String] path to the yaml file. # @return [RedBird::TileSet] # @author Frederico Linhares def self.from_yml(data_dir, tile_file, palette) yaml_file = data_dir + tile_file data = YAML.load_file(yaml_file) texture_path = data_dir + data["texture"] return self.new(texture_path, palette, data["width"], data["height"]) end end |
#tiles ⇒ Array<RedBird::TileSet::Sprite> (readonly)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/red_bird/tile_set.rb', line 16 class TileSet attr_reader :tiles, :tile_width, :tile_height # @param texture_file [String] this method uses the path as argument to # create a {RedBird::Texture}. # @param tile_width [Integer] width of each tile. # @param tile_height [Integer] height of each tile. # @author Frederico Linhares def initialize(texture_file, texture_palette, tile_width, tile_height) @texture = RedBird::Texture.new(texture_file, texture_palette) @tile_width = tile_width @tile_height = tile_height horizontal_tiles = @texture.width / @tile_width vertical_tiles = @texture.height / @tile_height @tiles = Sprite.grid( @texture, 0, 0, horizontal_tiles, vertical_tiles, @tile_width, @tile_height) end # Load information from a yaml file and uses it create an instance of this # class. # # @param data_dir [String] path to the directory containing the yaml and # other files referenced in the yaml. # @param tile_file [String] path to the yaml file. # @return [RedBird::TileSet] # @author Frederico Linhares def self.from_yml(data_dir, tile_file, palette) yaml_file = data_dir + tile_file data = YAML.load_file(yaml_file) texture_path = data_dir + data["texture"] return self.new(texture_path, palette, data["width"], data["height"]) end end |
Class Method Details
.from_yml(data_dir, tile_file, palette) ⇒ RedBird::TileSet
Load information from a yaml file and uses it create an instance of this class.
46 47 48 49 50 51 52 53 |
# File 'lib/red_bird/tile_set.rb', line 46 def self.from_yml(data_dir, tile_file, palette) yaml_file = data_dir + tile_file data = YAML.load_file(yaml_file) texture_path = data_dir + data["texture"] return self.new(texture_path, palette, data["width"], data["height"]) end |