Gambas Tile System

From PigaLore
Jump to navigationJump to search
Alpha build of a port to Lazarus

The Gambas Tile System is a tiling engine being written by Piga Software for use in its later projects. It is to form the basis of revamped versions of the Gambas Platform Engine, Gambas Genie and others. It is designed to be a flexible and resource efficient renderer allowing for easy scrolling and scalability.


In the final implementation there are three graphical layers made up of three distinct objects.

  • Tiles: the lowest layer of tiles that make up the basis of the world in small grid blocks. Persistent but can be reset or hidden. E.g. grass, stone, water.
  • Attributes: larger graphics drawn atop the tile layer and usually static but still mutable. E.g. trees, decor, collectibles.
  • Agents: dynamic elements that are drawn as independent entities over the world and move or animate frequently. E.g. players, NPCs, enemies.
    • Structures: dynamic, animated, but largely stationary agents such as buildings, machinery or similar.
    • Beings: used for frequently moving entities utilizing aspects of the Gambas Performance System and artificial intelligence.

A similarly named and functioning scheme is used in PS Tech, but with an added height system.

Fixed Version[edit]

Technical demo

In late December 2012, while doing performance testing on a low-end workstation machine while Nomad awaited a replacement power adapter, Graham Wilson began experimenting with several new systems of rendering. His first engines in Gambas from 2007-2009 were based on using PictureBox or Label controls in Qt 3 (see the original Windys), which lacked transparency when placed over other controls in Gambas 1. This lead him to adopt DrawingArea controls when he moved on to Gambas 2 full time in 2010, but the graphical load of drawing all elements, including backgrounds and moving entities, at once was proving taxing.

So he started testing various approaches with the intent of allowing users to select the one that best suited them. This involved testing using the PictureBox again in Childish Cannoneer (also done to aid in potential porting to Visual Basic.Net), as well as utilizing the DrawingArea rendering used in the Gambas Arcade Engine games, as well as experiments with using GLArea controls; this was adjacent to his nascent development of the OpenGL based PS Tech in the hope of taking advantage of hardware acceleration.

After further research, this was plan was modified and unified in January 2014 towards the idea of a single renderer based on the strengths of each system, using the DrawingArea for terrain and environment and PictureBox controls for units, allowing for them to be re-drawn separately from the game map. This was not previously viable until the GTK 3 and Qt 5 toolkits were adopted by Gambas 3 providing transparency for controls. This approach has proven consistently reliable and performant, with equivalent or less CPU load than comparable implementations in Pygame and similar. A version of this without tiling is present in the latest version of Piga's Santa Drop Down from 2016 and other games on Gambas Arcade Engine 2.0.

This lead to the the "Smooth Movement + Diagonals" demo released on September 1, 2014, wherein tile data is stored in a two-dimensional array that is displayed within a DrawingArea with a PictureBox used for the player character. This draft was later used as the basis for Hull Breach, created for the December 2020 LibreJam contest, and had also been forked and modified for other in-house projects that have not yet been finalized.

Scrolling Version[edit]

Development screenshot

Although decent for single screen games, the use of this tiling system proved cumbersome when adding scrolling. If done directly by translating the drawing area, the amount of tiles required to be drawn with a larger world at once proved too demanding. With that limitation in mind, development began in 2015 towards creating a system that would select only the tiles necessary to render while storing all the rest in memory. After a major breakthrough in 2018 for the adaptive tiling interface, work began on populating tile worlds in the latter part of 2019 by coordinating the dynamic elements as well as adding in the option of background props that reside directly over the tile layer.