https://github.com/skyvault/nim-tiled
Tiled map loader for the Nim programming language
https://github.com/skyvault/nim-tiled
game-development nim nim-lang nim-language tiled tiled-map-editor tmx tmx-parser
Last synced: 23 days ago
JSON representation
Tiled map loader for the Nim programming language
- Host: GitHub
- URL: https://github.com/skyvault/nim-tiled
- Owner: SkyVault
- License: mit
- Created: 2018-08-03T19:23:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-18T18:55:23.000Z (about 2 years ago)
- Last Synced: 2023-03-04T05:38:56.634Z (about 2 years ago)
- Topics: game-development, nim, nim-lang, nim-language, tiled, tiled-map-editor, tmx, tmx-parser
- Language: Nim
- Size: 5.81 MB
- Stars: 20
- Watchers: 1
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Nim Tiled
[](https://github.com/yglukhov/nimble-tag)## Introduction
A tiled map loader for the [Nim](nim-lang.org) programming language. The Tiled map editor can be found [here](https://www.mapeditor.org/).
Documentation for the tiled file format can be found [here](https://doc.mapeditor.org/en/stable/).Example
```nim
echo "Loaded the tiled map: ", loadTiledMap("tilemap.tmx").orDefault
```Example with error handling
```nim
let res = loadTiledMap("tilemap.tmx")if res.isOk:
echo "Loaded the tiled map: ", res.tiledMap
```## Documentation
Generate documentation by running the `nimble docs` command
## Example using [Windy](https://github.com/treeform/windy), [Pixie](https://github.com/Vladar4/sdl2_nim) and [Boxy](https://github.com/treeform/boxy)
### Infinite Tilemap demo
[Infinite Tilemap demo](https://github.com/SkyVault/nim-tiled-demo)
```nim
import windy, boxy, pixie, opengl, options, os, nim_tiledwhen isMainModule:
var window = newWindow("Tiled Map Demo!", ivec2(640, 640))
window.makeContextCurrent()
loadExtensions()var bxy = newBoxy()
let
tiledMap = loadTiledMap("res/TestArea.tmx").orDefault
tileset = tiledMap.tilesets[0]
tilesetImage = readImage("res".joinPath tileset.image.get().source)proc renderTile(key: string, gid: Tile) =
if not bxy.contains(key):
let
img = newImage(tileset.tilewidth, tileset.tileheight)
ctx = newContext(img)
tw = tileset.tilewidth.float
th = tileset.tileheight.float
rx = (gid mod tileset.columns).float * tw
ry = (gid.float / tileset.columns.float).int.float * thctx.drawImage(tilesetImage, rect(vec2(rx.float, ry.float), vec2(tw, th)),
rect(vec2(), vec2(tw, th)))bxy.addImage(key, img)
while not window.closeRequested:
glClear(GL_COLOR_BUFFER_BIT)
bxy.beginFrame(window.size)for layer in tiledMap.layers:
if layer.kind == tiles:
for chunk in layer.data.chunks:
for x in 0.. 0:
renderTile(key, gid - 1)
bxy.drawImage(key, pos = vec2(200.0, 128.0) + vec2(((
chunk.x.int + x) * tw.int).float, ((chunk.y.int + y) *
th.int).float))bxy.endFrame()
window.swapBuffers()
pollEvents()
```