Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hxdefold/hxdefold

Haxe/Lua externs for Defold game engine
https://github.com/hxdefold/hxdefold

defold-game-engine haxe lua lua-externs

Last synced: 8 days ago
JSON representation

Haxe/Lua externs for Defold game engine

Awesome Lists containing this project

README

        

![image](https://cloud.githubusercontent.com/assets/576184/15849567/80f4ada8-2c93-11e6-8430-5b5dbe5e58a3.png)

# Haxe support library for the [Defold](https://www.defold.com/) game engine

![Defold API version: 1.6.4](https://img.shields.io/badge/api%20version-1.6.4-orange.svg)

This library allows writing beautiful [Haxe](https://haxe.org/) code for the [Defold](https://www.defold.com/) game engine \o/

## Features
- Fully typed Defold API with proper compile-time errors and IDE services.
- Type-safe game object messages and properties with zero overhead.
- Strengths of Haxe without compromises: powerful type system, meta-programming, static optimizations, dead code elimination and cross-target code sharing.
- Defold hot reloading is now supported!

## Quick start

(assuming you already [installed Haxe](https://haxe.org/download/)😊)

- Install this library:
- From this repo: `haxelib git hxdefold https://github.com/hxdefold/hxdefold`
- Or from [lib.haxe.org](https://lib.haxe.org/): `haxelib install hxdefold`
- Run `haxelib run hxdefold init` inside your Defold project. It will create a sample `Hello.hx` script component class and a `build.hxml` for building it.
- Read the comments in these files to quickly get some idea.
- Build with `haxe build.hxml` to get the lua output.
- Add `Hello.script` to your game object in the editor and observe the greeting in the debug console.
- Proceed with writing well-structured, expressive and type safe code for your Defold game.

## How does it look like

```haxe
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 {

// 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](http://hxdefold.github.io/hxdefold/).

Migration to v2 is documented in the [v2 pull request](https://github.com/hxdefold/hxdefold/pull/37).

Details about usage can be found on [the wiki](https://github.com/hxdefold/hxdefold/wiki).

And here are some example Defold projects, ported from Lua:
* https://github.com/hxdefold/hxdefold-bunnymark

## 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:

```lua
-- 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

- **Major** number will be incremented for significant reworks that are certainly forward-breaking.
- **Minor** number will be incremented when updating to a new Defold API version. These updates may come with forward-breaking changes.
- **Patch** version will be incremented for bug fixes and potentially backwards-breaking changes.

Note that this is not standard [semver](https://semver.org/), since we might potentially ship backwards-breaking changes that increment only the patch number.

| hxdefold | Haxe | Defold API |
|:--------:|:----:|:----------:|
| 2.0.* | 4.3 | 1.6.4 |

## Logo

Made by the awesome [**@markknol**](https://github.com/markknol). Check out [his website](https://blog.stroep.nl/) for more art&code!