{"id":26600856,"url":"https://github.com/skyvault/nim-tiled","last_synced_at":"2025-04-09T16:24:23.170Z","repository":{"id":40696624,"uuid":"143465121","full_name":"SkyVault/nim-tiled","owner":"SkyVault","description":"Tiled map loader for the Nim programming language","archived":false,"fork":false,"pushed_at":"2023-02-18T18:55:23.000Z","size":6091,"stargazers_count":20,"open_issues_count":4,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-04T05:38:56.634Z","etag":null,"topics":["game-development","nim","nim-lang","nim-language","tiled","tiled-map-editor","tmx","tmx-parser"],"latest_commit_sha":null,"homepage":null,"language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SkyVault.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-03T19:23:33.000Z","updated_at":"2023-03-04T05:38:56.635Z","dependencies_parsed_at":"2023-02-09T20:45:45.885Z","dependency_job_id":null,"html_url":"https://github.com/SkyVault/nim-tiled","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkyVault%2Fnim-tiled","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkyVault%2Fnim-tiled/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkyVault%2Fnim-tiled/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SkyVault%2Fnim-tiled/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SkyVault","download_url":"https://codeload.github.com/SkyVault/nim-tiled/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245152204,"owners_count":20569391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game-development","nim","nim-lang","nim-language","tiled","tiled-map-editor","tmx","tmx-parser"],"created_at":"2025-03-23T18:35:44.934Z","updated_at":"2025-03-23T18:35:47.860Z","avatar_url":"https://github.com/SkyVault.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nim Tiled\n[![nimble](https://raw.githubusercontent.com/yglukhov/nimble-tag/master/nimble.png)](https://github.com/yglukhov/nimble-tag)\n\n## Introduction\n\nA tiled map loader for the [Nim](nim-lang.org) programming language. The Tiled map editor can be found [here](https://www.mapeditor.org/).\nDocumentation for the tiled file format can be found [here](https://doc.mapeditor.org/en/stable/).\n\nExample\n\n```nim\necho \"Loaded the tiled map: \", loadTiledMap(\"tilemap.tmx\").orDefault\n```\n\nExample with error handling\n\n```nim\nlet res = loadTiledMap(\"tilemap.tmx\")\n\nif res.isOk:\n  echo \"Loaded the tiled map: \", res.tiledMap\n```\n\n## Documentation\n\n​\tGenerate documentation by running the `nimble docs` command\n\n## Example using [Windy](https://github.com/treeform/windy), [Pixie](https://github.com/Vladar4/sdl2_nim) and [Boxy](https://github.com/treeform/boxy)\n\n### Infinite Tilemap demo\n\n[Infinite Tilemap demo](https://github.com/SkyVault/nim-tiled-demo)\n\n```nim\nimport windy, boxy, pixie, opengl, options, os, nim_tiled\n\nwhen isMainModule:\n  var window = newWindow(\"Tiled Map Demo!\", ivec2(640, 640))\n  window.makeContextCurrent()\n  loadExtensions()\n\n  var bxy = newBoxy()\n\n  let\n    tiledMap = loadTiledMap(\"res/TestArea.tmx\").orDefault\n    tileset = tiledMap.tilesets[0]\n    tilesetImage = readImage(\"res\".joinPath tileset.image.get().source)\n\n  proc renderTile(key: string, gid: Tile) =\n    if not bxy.contains(key):\n      let\n        img = newImage(tileset.tilewidth, tileset.tileheight)\n        ctx = newContext(img)\n        tw = tileset.tilewidth.float\n        th = tileset.tileheight.float\n        rx = (gid mod tileset.columns).float * tw\n        ry = (gid.float / tileset.columns.float).int.float * th\n\n      ctx.drawImage(tilesetImage, rect(vec2(rx.float, ry.float), vec2(tw, th)),\n          rect(vec2(), vec2(tw, th)))\n\n      bxy.addImage(key, img)\n\n  while not window.closeRequested:\n    glClear(GL_COLOR_BUFFER_BIT)\n    bxy.beginFrame(window.size)\n\n    for layer in tiledMap.layers:\n      if layer.kind == tiles:\n        for chunk in layer.data.chunks:\n          for x in 0..\u003cchunk.width.int:\n            for y in 0..\u003cchunk.height.int:\n              let\n                tw = tileset.tilewidth.float\n                th = tileset.tileheight.float\n                gid = chunk.tiles[x + y * chunk.width.int]\n                key = \"tile-\" \u0026 $gid\n\n              if gid \u003e 0:\n                renderTile(key, gid - 1)\n                bxy.drawImage(key, pos = vec2(200.0, 128.0) + vec2(((\n                    chunk.x.int + x) * tw.int).float, ((chunk.y.int + y) *\n                        th.int).float))\n\n    bxy.endFrame()\n    window.swapBuffers()\n    pollEvents()\n```\n\n![Preview](screenshot.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyvault%2Fnim-tiled","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyvault%2Fnim-tiled","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyvault%2Fnim-tiled/lists"}