nim_tiled

Tiled map loader for the Nim programming language

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License MIT
CI Status Passing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install nim_tiled
choosenim install nim_tiled
git clone https://github.com/SkyVault/nim-tiled

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
nim_tiled - - - - - - -

Source

Repository https://github.com/SkyVault/nim-tiled
Homepage https://github.com/SkyVault/nim-tiled
Registry Source nimble_official

README

Nim Tiled

nimble

Introduction

A tiled map loader for the Nim programming language. The Tiled map editor can be found here. Documentation for the tiled file format can be found here.

Example

echo "Loaded the tiled map: ", loadTiledMap("tilemap.tmx")

Example with error handling

try:
  let res = loadTiledMap("tilemap.tmx")
except TiledError as e:
  stderr.writeLine(e.msg)  

Documentation

​ Generate documentation by running the nimble docs command

Example using Windy, Pixie and Boxy

Infinite Tilemap demo

Infinite Tilemap demo

import windy, boxy, pixie, opengl, options, os, nim_tiled

when isMainModule:
  var window = newWindow("Tiled Map Demo!", ivec2(640, 640))
  window.makeContextCurrent()
  loadExtensions()

  var bxy = newBoxy()

  let
    tiledMap = loadTiledMap("res/TestArea.tmx")
    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 * th

      ctx.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..<chunk.width.int:
            for y in 0..<chunk.height.int:
              let
                tw = tileset.tilewidth.float
                th = tileset.tileheight.float
                gid = chunk.tiles[x + y * chunk.width.int]
                key = "tile-" & $gid

              if gid > 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()

Preview