Home

Awesome

image

Haxe support library for the Defold game engine

Defold API version: 1.6.4

This library allows writing beautiful Haxe code for the Defold game engine \o/

Features

Quick start

(assuming you already installed Haxe😊)

How does it look like

import defold.support.Script;

// component class that defines the callback methods
// after compiling Haxe, the `Hello.script` will appear in the Defold project that can be attached to game objects
class Hello extends Script<HelloData> {

    // fields with @property annotation will show up in the editor
    @property var power:Int = 9000;

    // the `init` callback method
    override function init() {
        trace('Haxe is over ${power}!'); // will be printed to the debug console
    }

    // the `update` callback method
    override function update(dt:Float) {}
}

Documentation

Here is the API reference.

Migration to v2 is documented in the v2 pull request.

Details about usage can be found on the wiki.

And here are some example Defold projects, ported from Lua:

How does it work?

Since version 3.4, Haxe supports compiling to Lua, making it possible to use Haxe with Lua-based engines, such as Defold.

However, this requires a bit of autogenerated glue code, because Defold expects scripts to be in separate files, while Haxe compiles everything in a single lua module. So what we do, is generate a simple glue .script file for each class extending the magic defold.support.Script base class (there are also GuiScript and RenderScript).

For example, for the Hello script from this README, this glue code is generated in the Hello.script file:

-- Generated by Haxe, DO NOT EDIT (original source: src/Hello.hx:11: lines 11-16)

go.property("power", 9000)

require "main"

function init(self)
    _hxdefold_.Hello_init(self)
end

You can then add this script to the game objects in the Defold Editor.

Versions

Note that this is not standard semver, since we might potentially ship backwards-breaking changes that increment only the patch number.

hxdefoldHaxeDefold API
2.0.*4.31.6.4

Logo

Made by the awesome @markknol. Check out his website for more art&code!