This guide takes you through writing a simple application using Tilengine. The application will initialize the engine, create a window, load a background layer and a sprite, and exit when the user closes the window. This guide will introduce a few of the most commonly used functions, but there are many more.
In the source files of your application where you use Tilengine, you need to include the header file:
First step is initialize the engine with TLN_Init. This takes the following parameters, that will remain constant and cannot be changed once the engine is initialized:
This creates a framebuffer of 480x272 pixels, 4 background layers, 64 sprites and no palette animations.
By default Tilengine doesn't create a window when it's initialized, because it is designed to act as a slave renderer for any framework or environment. However it also provides its own window environment.
To create a window, call TLN_CreateWindow after having called TLN_Init:
This creates a default window. There are some key bindings:
Esc
to close the windowAlt
+ Enter
to toggle full-screen/windowedBackspace
to toggle on/off built-in CRT effect (default on)Tilemaps with the layout of backgrounds are stored inside .tmx
files. Each .tmx
file can contain many tilemap and object layers. To load one, call TLN_LoadTilemap with the filename and the name of the layer to load, and returns a TLN_Tilemap handler:
Once the tilemap is loaded, it must be assigned to one of the available background layers with TLN_SetLayerTilemap, passing the layer index and the loaded tilemap:
By default the tilemap is aligned to the top-left corner of the screen (position 0,0). To move it to another position, use TLN_SetLayerPosition passing the layer index and the [x, y] position inside the tilemap:
This advances the viewport of layer 0 32 pixels to the right.
Spritesets containing the animation frames for a sprite are contained inside .png
files with layout information in associated .txt
, .csv
, or .json
text files. They're loaded with TLN_LoadSpriteset passing the .png file, and return a TLN_Spriteset handler:
Once the spriteset is loaded, it must be assigned to one of the available spritest with TLN_SetSpriteSet, passing the sprite index and the loaded spriteset:
By default, the sprite is initialized at position 0,0, (top left corner). To move it to another location, use TLN_SetSpritePosition passing the sprite index, and the, x,y screen coordinates:
A spriteset contains many frames of animation. By default a sprite is assigned the first image of the spriteset. Images in a spriteset are referenced with their index, starting from 0. Indexes can be obtained from sprite name with TLN_FindSpritesetSprite and assigned with TLN_SetSpritePicture passing sprite index and frame index:
A good practice is to cache the indexes of required frames so they don't need to be searched every time.
On each frame the window must be updated with TLN_ProcessWindow, which returns true
until the user requests closing the window, and the frame must be rendered with TLN_DrawFrame. Parameter "frame" is deprecated and can be left as 0:
The window will continue active until closed or Esc
key is pressed.
Now it's possible to create a simple program that initializes the engine, creates a window, and sets up a background layer and a sprite loaded from asset files:
To build for Linux, just link with libTilengine.so
library:
Building for Windows requires linking to Tilengine.lib
:
Last update on Tue Aug 29 2023 for Tilengine 2.15.1