0010. Architecture of the Ebitengine Game Engine

0010. Architecture of the Ebitengine Game Engine

Watch the associated video on YouTube or MakerTube

Watch on YouTube

Introduction #

In this tutorial we will learn how the Ebitengine game engine is structured.

The code for this tutorial is available here. Please consider donating if you find this tutorial helpful.

Single-Threaded Game Loop #

Ebitengine executes a game’s Layout, Update and Draw methods in series, never in parallel.

In other words, as far as these specific methods go, the application runs in a single thread.

Thus, we do not need to apply any locking in these methods to prevent parallel execution.

When using Ebitengine, it is our choice if and when to execute code in additional threads.

Still, it is beneficial to utilize multiple threads, as most systems have more than one CPU core available.

Maintaining Tick Rate #

Ebitengine runs a loop which calculates the number of Update calls needed based on the current time and TPS.

This means between two Draw calls, there may be zero, one or more Update calls.

While the number of Update calls may fluctuate between frames, Ebitengine takes measures to smooth the tick rate.

For example, when a game is running at 60 ticks per second and 120 frames per second, we may see the following calls:

  1. Update
  2. Draw
  3. Draw
  4. Update
  5. Draw
  6. Draw
  7. Etc.

Because of fluctuations in performance, we may see more or less Update or Draw calls in any specific period.

Layout is also periodically called, but is not included in the above list for clarity.

Everything is an ebiten.Image #

The screen canvas we draw onto is an ebiten.Image. Any offscreen images we create are the same type.

The canvas is different from offscreen images only in the way it is automatically scaled up or down to fit the window.

Otherwise, the screen image and any offscreen images behave the same, and have the same draw operations available.

This makes it easy to transition code from drawing directly onto the screen to drawing using offscreen images.

Extra: Why I Enjoy Using Ebitengine #

I enjoy using Ebitengine to create games for many reasons, including:

API Design #

Now that we have taken a closer look at Ebitengine’s design, we can appreciate its benefits:

  • The API is simple and easy to understand
  • The API provides a wide range of features without excessive complexity
  • Because the API is simple, it is highly portable, allowing Ebitengine to support many platforms

Ebitengine’s simple API abstracts away much of the complexity involved in developing graphical software.

Less is More #

Ebitengine’s API provides building blocks for creating graphical applications.

When we want to create something more complex using these building blocks, we have two options:

  • Implement more complex features from scratch ourselves
  • Import and use relevant libraries created by the community of Ebitengine developers

Libraries created by community members are shared under various free and open source software licenses.

Some such libraries can be found in the Awesome Ebitengine directory.

For example, several libraries for creating graphical user interfaces are available.

Each member of the community of developers using Ebitengine offers a unique perspective and approach.

This results in multiple packages providing the same or similar functionality, but with different implementations and APIs.

Permissive License #

Note: Describing software licensing in any detail is outside the scope of this tutorial. If you are unfamiliar with commonly used software licenses, or the differences between copyleft and permissive licenses, please see this comparison table.

Ebitengine is available under the Apache License 2.0 software license, which is a permissive license.

This means that developers using Ebitengine are not required to release the source code of their application.

This allows developers to create and use proprietary software in combination with Ebitengine, so long as the license terms are followed. Developers may choose at a later time to release their source code, or may never release their source code.

As an advocate of free software, I recommend that all developers release their source code under an appropriate license.

Still, it is worth acknowledging the usefulness of being able to choose whether (and when) to release any source code.

No fees or royalties are required when using Ebitengine. Developers may choose to support Ebitengine at their discretion.


Stay tuned for the next tutorial, Creating and Loading Tilemaps Using Ebitengine.

Please consider donating if you found this tutorial helpful.