Update for Tilengine 2.14.0
Remove accidental bool return from some procs
Update for Tilengine 2.13.2
Nim bindings for Tilengine - a free, cross-platform 2D graphics engine for creating classic/retro games with tile maps, sprites and palettes.
Refer to the C docs and peek at the Nim source to get a feel for things.
These Nim bindings are close to the C bindings, with the following changes:
TLN_CreateBitmap
→ createBitmap
TLN_GetBitmapWidth
→ getWidth
Tile
objects have accessors (e.g. t.flipx = true
) so you don't have to get your hands dirty with bitwise operations.cwfVsync
, errFileNotFound
BlendNone
, InputLeft
TLN_SetLayerPixelMapping(layer, NULL)
→ layer.disablePixelMapping()
ptr UncheckedArray[T]
is used instead of ptr T
Note: these bindings do use manual memory management, so you must call map.delete()
etc. to avoid leaks.
import tilengine
# Initialise the engine
let engine = init(400, 240, numLayers = 1, numSprites = 0, numAnimations = 0)
# Load a tilemap
let map = loadTilemap("assets/forest/map.tmx")
# Modify a tile
let (x, y) = (10, 12)
var tile = map.getTile(y, x)
tile.flipx = true
map.setTile(y, x, tile)
# Assign tilemap to layer
const layer = Layer(0)
layer.setTilemap(map)
# Create window and run game loop
createWindow()
while processWindow():
drawFrame()
# Cleanup
map.delete()
deleteWindow()
deinit()
You will need the following shared libraries installed on your system or placed in the same directory as your executable.
Clone the repo, use nimble to install it, then try building the example!
git clone https://git.sr.ht/~exelotl/nim-tilengine
cd nim-tilengine
nimble install
cd examples
nim c -r example.nim
Any questions, just send an email to the public mailing list at ~exelotl/public-inbox@lists.sr.ht. You can also send contributions, see git-send-email.io to learn how!