Giter Site home page Giter Site logo

hxdefold's Introduction

image

Haxe support library for the Defold game engine

Build Status Defold API version: 1.2.169

This library allows writing beautiful Haxe code for KING's Defold 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๐Ÿ˜Š)

  • Install this library (from this repo): haxelib git hxdefold https://github.com/hxdefold/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

// sample script component code

// definition of the component data, passed as `self` to the callback methods
typedef HelloData = {
	// fields with @property annotation will show up in the editor
	@property(9000) var power:Int;
}

// 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 defold.support.Script<HelloData> {
	// the `init` callback method
	override function init(self:HelloData) {
		trace('Haxe is over ${self.power}!'); // will be printed to the debug console
	}
}

Documentation

Here is the API reference.

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.

Issues

If you're getting an error like attempt to call global '_hx_e' (a nil value) at run-time, that means you're compiling the project using the Haxe compilation server, which is happening by default when building through Visual Studio Code Haxe extension. You can disable the usage if the compilation server for building by setting "haxe.enableCompilationServer": false in your workspaces settings.json. Alternatively you can grab a nightly of the Haxe compiler version, because the bug was already fixed there. See more info here and here if you're curious. :-)

Logo

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

hxdefold's People

Contributors

nadako avatar haath avatar codescapade avatar markknol avatar sebthom avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.