Defold and TypeScript Pt. 2

As of February 1, 2024, I became a maintainer of the TS-Defold project. Thanks to Justin Walsh for having me on the team!

(I have a weird affinity for doing chores like updating dependencies. It’s like cleaning a house; a little tedious, but so rewarding.)

Here’s a quick recap of everything I’ve been up to.

TS-Defold official

  • The website is now refreshed with updated info
  • I’ve maintained the official templates and template-boom: migrated them to the latest plugins
  • I’ve contributed a bucket-load of types to the Library
  • Kept hacking away at my fork of Defold types

TypeScriptToLua plugins

Defold plugins

  • Updated my PRNG plugin with some new convenience methods
  • Created setv by combining elements of two popular plugins
  • Started on a refactor of estring
  • Archived etable
  • Archived emath

Other tools

  • Made tsd-ext-type-gen to parse script_api files in Defold extensions to export TypeScript types
  • Created def-html5-opt to optimize Defold HTML5 exports

Aeroblast

I’ve released a game on itch.io: Aeroblast

Pixel art plane and title text Aeroblast on a pixelated cloud background

Aeroblast is a simple but addictive top-down auto-shooter. Move using the cursor keys or WASD. Aim at enemies – your character will automatically shoot. Collect power-ups to gain a faster fire rate, restore health, and more. Win by surviving the full ten minute play time.

The game’s full source code is available on Github.

Exploring Defold and TypeScript

The Defold game engine has been in my bookmarks folder for months now, but I’ve only just recently started to make things with the engine.

Defold fits a number of my criteria for a great game engine:

  • It exports to the web, and performance in the browser is actually good!
  • It effortlessly exports to all other platforms too
  • It’s well suited for 2D games (the editor can plop down objects at nice round X and Y coordinates)
  • It’s free and open-source (technically there are limitations in the Defold license, but nothing that affects making games)
  • It’s extremely well maintained with monthly updates

However, I was initially put off by the use of Lua as its scripting language. I had never used Lua, so that was a barrier to entry. It’s also a dynamically typed language, which is a pain to debug.

Then I discovered the TypeScript community extensions (@ts-defold) for Defold. These tools allow using Defold with TypeScript, a strongly typed language that I already know and enjoy.

It turns out I’m more productive working on tools than games, so here’s what I’ve done so far:

  • Created a TypeScriptToLua (TSTL) plugin that will strip the last extension from files that have multiple extensions. This is used to handle Defold’s specific file extensions, so a file name like `player.script.ts` is output to `player.script` instead of the incorrect `player.script.lua`. This plugin can replace the patch file that come with @ts-defold, so you’re no longer locked to early versions of TSTL.
  • Tweaked the type definitions for the Defold game engine from @ts-defold/types. I’ve been slowly describing more of the types that were left as unknown in the original output. I’m not sure how useful this is to the average developer, but I find it satisfying.
  • Created type definitions for @britzl’s new boom framework.
  • Created a project template that includes all of the above.
  • Created type definitions for @thejustinwalsh’s xmath framework. The comments are copied from Defold’s vmath library, so I’m not sure they’re 100% accurate to xmath’s implementation, but they seem pretty close.

I also played around with using Chat-GPT to generate some native extensions. My C++ knowledge is limited, but I was able to cajole the AI into creating something that actually works.

There are already community extensions that cover these use cases, so I doubt my libraries will see much use. Still, it’s fun to see how easy it is to extend the engine, despite being a complete newcomer.

Clones of Vampire Survivors are in the zeitgeist now, so I’m currently trying to create a really simple one of those. I’ll open-source the whole project when it’s done.