This is a library for loading Tiled map files in DragonRuby Game Toolkit.
It supports TMX format directly allowing skip exporting to json or csv files step.
- Create a
lib
directory inside the base directory of your DR game. - Copy
lib/tiled
directory to createdlib
. - Add
require 'lib/tiled/tiled.rb
to the top of yourapp/main.rb
file.
This is the simplest way to use library:
require 'lib/tiled/tiled.rb'
def tick(args)
if args.state.tick_count.zero?
map = Tiled::Map.new("maps/map.tmx")
map.load
args.state.map = map
args.outputs.static_sprites << map.layers.first.sprites
end
end
The tilesets and spritesheets used in map should be placed inside your game dir, for example you should save map files inside map dir and spritesheets inside sprites dir.
ground_layer = map.layers['ground'] # Get layer by name
collisions_layer = map.layers['collisions']
layer_5 = map.layers.at(5) # Get layer by index
map.layers.select(&:visible?) # Get visible layers
You can access individual tiles using #tile_at(x, y)
method.
collisions_layer = map.layers['collisions']
if collisions_layer.tile_at(new_x, new_y).properties.passable?
player.move(new_x, new_y)
end
# clone drtiled somewhere
./dragonruby /path/to/drtiled
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
- Thanks to Pipoya for beautiful arts and sample map used in samples!
- Kenney Simplified Platformer Pack used for loose tiles map sample