Haxe

  • Template: cart_haxe - press "Use this template" and you have a working game.
  • Docker image: ghcr.io/notnullgames/null0-cart-haxe:latest (linux/amd64 only - runs emulated on Apple Silicon)
  • Your code: cart/Main.hx, compiled with haxe, HL/C + wasi-sdk
  • Bindings: carts/haxe/Null0.hx (baked into the docker image for you)
  • WASI is available, so ordinary file and stdio calls work.

building

You do not install haxe, HL/C + wasi-sdk - the docker image has it, and the current null0 bindings, baked in. That is the whole point: there is nothing in your project to keep in sync with the engine.

docker run --rm --user $(id -u):$(id -g) --platform linux/amd64 \
  -v ./cart:/src -v ./webroot:/out \
  ghcr.io/notnullgames/null0-cart-haxe:latest mygame

The template wraps that in npm start, which also serves the result and rebuilds when you save.

Haxe notes

  • Callbacks are closures you assign (Null0.onUpdate = ...), not exports.
  • No try/catch: wasm exception-handling is not available in the host interpreter.

a cart, in Haxe

This is carts/haxe/simple/Main.hx in the engine repo - the same file CI builds into the cart below, so it always compiles.

class Main {
  static function main() {
    Null0.onLoad = () -> {
      Null0.clear(Null0.BLUE);
      Null0.drawCircle(100, 100, 50, Null0.RED);
      Null0.drawText(Null0.FONT_DEFAULT, "hello from haxe", 130, 90, Null0.WHITE);
    };

    Null0.onUpdate = () -> {
      // runs every frame
    };
  }
}

// other callbacks you can set in main():
//
//   Null0.onUnload = () -> {}
//   Null0.onButtonUp = (button:GamepadButton, player:Int) -> {}
//   Null0.onButtonDown = (button:GamepadButton, player:Int) -> {}
//   Null0.onKeyUp = (key:Key) -> {}
//   Null0.onKeyDown = (key:Key) -> {}
//   Null0.onMouseDown = (button:MouseButton) -> {}
//   Null0.onMouseUp = (button:MouseButton) -> {}
//   Null0.onMouseMoved = (x:Single, y:Single) -> {}
//
// types live in the Null0 module: import Null0.Color, import Null0.Key, ...
carts/haxe/simple/Main.hx

callbacks

A cart implements the callbacks it cares about. In Haxe they look like this:

Null0.onUpdate = () -> {}

See anatomy of a cart for the full list and what each one is passed.

more Haxe carts

the API, in Haxe

Every null0 function, spelled the way Haxe spells it. These are read out of the generated bindings themselves, so they match what your editor completes.

colors (7)

Tint a color with another color.

public static function colorTint(color:Color, tint:Color):Color

Fade a color.

public static function colorFade(color:Color, alpha:Single):Color

Change the brightness of a color.

public static function colorBrightness(color:Color, factor:Single):Color

Invert a color.

public static function colorInvert(color:Color):Color

Blend 2 colors together.

public static function colorAlphaBlend(dst:Color, src:Color):Color

Change contrast of a color.

public static function colorContrast(color:Color, contrast:Single):Color

Interpolate colors.

public static function colorBilinearInterpolate(color00:Color, color01:Color, color10:Color, color11:Color, coordinateX:Single, coordinateY:Single):Color
graphics (75)

Create a new blank image.

public static function newImage(width:Int, height:Int, color:Color):Image

Copy an image to a new image.

public static function imageCopy(image:Image):Image

Create an image from a region of another image.

public static function imageSubimage(image:Image, x:Int, y:Int, width:Int, height:Int):Image

Clear the screen.

public static function clear(color:Color):Void

Draw a single pixel on the screen.

public static function drawPoint(x:Int, y:Int, color:Color):Void

Draw a line on the screen.

public static function drawLine(startPosX:Int, startPosY:Int, endPosX:Int, endPosY:Int, color:Color):Void

Draw a filled rectangle on the screen.

public static function drawRectangle(posX:Int, posY:Int, width:Int, height:Int, color:Color):Void

Draw a filled triangle on the screen.

public static function drawTriangle(x1:Int, y1:Int, x2:Int, y2:Int, x3:Int, y3:Int, color:Color):Void

Draw a filled ellipse on the screen.

public static function drawEllipse(centerX:Int, centerY:Int, radiusX:Int, radiusY:Int, color:Color):Void

Draw a filled circle on the screen.

public static function drawCircle(centerX:Int, centerY:Int, radius:Int, color:Color):Void

Draw a filled polygon on the screen.

static function _drawPolygon(points:Array<Vector>, color:Color):Void

Draw a filled arc on the screen.

public static function drawArc(centerX:Int, centerY:Int, radius:Single, startAngle:Single, endAngle:Single, segments:Int, color:Color):Void

Draw a filled round-rectangle on the screen.

public static function drawRectangleRounded(x:Int, y:Int, width:Int, height:Int, cornerRadius:Int, color:Color):Void

Draw an image on the screen.

public static function drawImage(src:Image, posX:Int, posY:Int):Void

Draw a tinted image on the screen.

public static function drawImageTint(src:Image, posX:Int, posY:Int, tint:Color):Void

Draw an image, rotated, on the screen.

public static function drawImageRotated(src:Image, posX:Int, posY:Int, degrees:Single, offsetX:Single, offsetY:Single, filter:ImageFilter):Void

Draw an image, flipped, on the screen.

public static function drawImageFlipped(src:Image, posX:Int, posY:Int, flipHorizontal:Bool, flipVertical:Bool, flipDiagonal:Bool):Void

Draw an image, scaled, on the screen.

public static function drawImageScaled(src:Image, posX:Int, posY:Int, scaleX:Single, scaleY:Single, offsetX:Single, offsetY:Single, filter:ImageFilter):Void

Draw some text on the screen.

public static function drawText(font:Font, text:String, posX:Int, posY:Int, color:Color):Void

Save an image to persistant storage.

public static function saveImage(image:Image, filename:String):Void

Load an image from a file in cart.

public static function loadImage(filename:String):Image

Resize an image, return copy.

public static function imageResize(image:Image, newWidth:Int, newHeight:Int, filter:ImageFilter):Image

Scale an image, return copy.

public static function imageScale(image:Image, scaleX:Single, scaleY:Single, filter:ImageFilter):Image

Replace a color in an image, in-place.

public static function imageColorReplace(image:Image, color:Color, replace:Color):Void

Tint a color in an image, in-place.

public static function imageColorTint(image:Image, color:Color):Void

Fade a color in an image, in-place.

public static function imageColorFade(image:Image, alpha:Single):Void

Copy a font to a new font.

public static function fontCopy(font:Font):Font

Scale a font, return a new font.

public static function fontScale(font:Font, scaleX:Single, scaleY:Single, filter:ImageFilter):Font

Load a BMF font from a file in cart.

public static function loadFontBmf(filename:String, characters:String):Font

Load a BMF font from an image.

public static function loadFontBmfFromImage(image:Image, characters:String):Font

Measure the size of some text.

static function _measureText(font:Font, text:String, textLength:Int):Dimensions

Meaure an image (use 0 for screen).

public static function measureImage(image:Image):Dimensions

Load a TTY font from a file in cart.

public static function loadFontTty(filename:String, glyphWidth:Int, glyphHeight:Int, characters:String):Font

Load a TTY font from an image.

public static function loadFontTtyFromImage(image:Image, glyphWidth:Int, glyphHeight:Int, characters:String):Font

Load a TTF font from a file in cart.

public static function loadFontTtf(filename:String, fontSize:Int):Font

Invert the colors in an image, in-place.

public static function imageColorInvert(image:Image):Void

Calculate a rectangle representing the available alpha border in an image.

public static function imageAlphaBorder(image:Image, threshold:Single):Rectangle

Crop an image, in-place.

public static function imageCrop(image:Image, x:Int, y:Int, width:Int, height:Int):Void

Crop an image based on the alpha border, in-place.

public static function imageAlphaCrop(image:Image, threshold:Single):Void

Adjust the brightness of an image, in-place.

public static function imageColorBrightness(image:Image, factor:Single):Void

Flip an image, in-place.

public static function imageFlip(image:Image, horizontal:Bool, vertical:Bool):Void

Change the contrast of an image, in-place.

public static function imageColorContrast(image:Image, contrast:Single):Void

Use an image as an alpha-mask on another image.

public static function imageAlphaMask(image:Image, alphaMask:Image, posX:Int, posY:Int):Void

Create a new image, rotating another image.

public static function imageRotate(image:Image, degrees:Single, filter:ImageFilter):Image

Create a new image of a gradient.

public static function imageGradient(width:Int, height:Int, topLeft:Color, topRight:Color, bottomLeft:Color, bottomRight:Color):Image

Unload an image.

public static function unloadImage(image:Image):Void

Unload a font.

public static function unloadFont(font:Font):Void

Clear an image.

public static function clearImage(destination:Image, color:Color):Void

Draw a single pixel on an image.

public static function drawPointOnImage(destination:Image, x:Int, y:Int, color:Color):Void

Draw a line on an image.

public static function drawLineOnImage(destination:Image, startPosX:Int, startPosY:Int, endPosX:Int, endPosY:Int, color:Color):Void

Draw a filled rectangle on an image.

public static function drawRectangleOnImage(destination:Image, posX:Int, posY:Int, width:Int, height:Int, color:Color):Void

Draw a filled triangle on an image.

public static function drawTriangleOnImage(destination:Image, x1:Int, y1:Int, x2:Int, y2:Int, x3:Int, y3:Int, color:Color):Void

Draw a filled ellipse on an image.

public static function drawEllipseOnImage(destination:Image, centerX:Int, centerY:Int, radiusX:Int, radiusY:Int, color:Color):Void

Draw a circle on an image.

public static function drawCircleOnImage(destination:Image, centerX:Int, centerY:Int, radius:Int, color:Color):Void

Draw a filled polygon on an image.

static function _drawPolygonOnImage(destination:Image, points:Array<Vector>, color:Color):Void

Draw a filled round-rectangle on an image.

public static function drawRectangleRoundedOnImage(destination:Image, x:Int, y:Int, width:Int, height:Int, cornerRadius:Int, color:Color):Void

Draw an image on an image.

public static function drawImageOnImage(destination:Image, src:Image, posX:Int, posY:Int):Void

Draw a tinted image on an image.

public static function drawImageTintOnImage(destination:Image, src:Image, posX:Int, posY:Int, tint:Color):Void

Draw an image, rotated, on an image.

public static function drawImageRotatedOnImage(destination:Image, src:Image, posX:Int, posY:Int, degrees:Single, offsetX:Single, offsetY:Single, filter:ImageFilter):Void

Draw an image, flipped, on an image.

public static function drawImageFlippedOnImage(destination:Image, src:Image, posX:Int, posY:Int, flipHorizontal:Bool, flipVertical:Bool, flipDiagonal:Bool):Void

Draw an image, scaled, on an image.

public static function drawImageScaledOnImage(destination:Image, src:Image, posX:Int, posY:Int, scaleX:Single, scaleY:Single, offsetX:Single, offsetY:Single, filter:ImageFilter):Void

Draw some text on an image.

public static function drawTextOnImage(destination:Image, font:Font, text:String, posX:Int, posY:Int, color:Color):Void

Draw a outlined (with thickness) rectangle on the screen.

public static function drawRectangleOutline(posX:Int, posY:Int, width:Int, height:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) triangle on the screen.

public static function drawTriangleOutline(x1:Int, y1:Int, x2:Int, y2:Int, x3:Int, y3:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) ellipse on the screen.

public static function drawEllipseOutline(centerX:Int, centerY:Int, radiusX:Int, radiusY:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) circle on the screen.

public static function drawCircleOutline(centerX:Int, centerY:Int, radius:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) polygon on the screen.

static function _drawPolygonOutline(points:Array<Vector>, thickness:Int, color:Color):Void

Draw a outlined (with thickness) arc on the screen.

public static function drawArcOutline(centerX:Int, centerY:Int, radius:Single, startAngle:Single, endAngle:Single, segments:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) round-rectangle on the screen.

public static function drawRectangleRoundedOutline(x:Int, y:Int, width:Int, height:Int, cornerRadius:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) rectangle on an image.

public static function drawRectangleOutlineOnImage(destination:Image, posX:Int, posY:Int, width:Int, height:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) triangle on an image.

public static function drawTriangleOutlineOnImage(destination:Image, x1:Int, y1:Int, x2:Int, y2:Int, x3:Int, y3:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) ellipse on an image.

public static function drawEllipseOutlineOnImage(destination:Image, centerX:Int, centerY:Int, radiusX:Int, radiusY:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) circle on an image.

public static function drawCircleOutlineOnImage(destination:Image, centerX:Int, centerY:Int, radius:Int, thickness:Int, color:Color):Void

Draw a outlined (with thickness) polygon on an image.

static function _drawPolygonOutlineOnImage(destination:Image, points:Array<Vector>, thickness:Int, color:Color):Void

Draw a outlined (with thickness) round-rectangle on an image.

public static function drawRectangleRoundedOutlineOnImage(destination:Image, x:Int, y:Int, width:Int, height:Int, cornerRadius:Int, thickness:Int, color:Color):Void
gui (10)

Begin a GUI window. Returns false if the window is collapsed or closed - skip its contents, but still call gui_end_window.

public static function guiBeginWindow(title:String, rect:Rectangle):Bool

End the current GUI window.

public static function guiEndWindow():Void

A button. Returns true when it is clicked.

public static function guiButton(label:String):Bool

A static text label.

public static function guiLabel(text:String):Void

A block of wrapping text.

public static function guiText(text:String):Void

A checkbox. Returns the (possibly changed) state.

public static function guiCheckbox(label:String, state:Bool):Bool

A slider. Returns the (possibly changed) value.

public static function guiSlider(value:Single, low:Single, high:Single):Single

Set the current layout row - the column widths (negative for flexible), and the row height.

static function _guiLayoutRow(widths:Array<Int>, height:Int):Void

Finish building the GUI for this frame. Called automatically at the end of update if you do not call it.

public static function guiEnd():Void

Draw the GUI to an image (0 is the screen).

public static function guiDraw(dst:Image):Void
input (12)

Has the key been pressed? (tracks unpress/read correctly.)

public static function keyPressed(key:Key):Bool

Is the key currently down?

public static function keyDown(key:Key):Bool

Has the key been released? (tracks press/read correctly.)

public static function keyReleased(key:Key):Bool

Is the key currently up?

public static function keyUp(key:Key):Bool

Has the button been pressed? (tracks unpress/read correctly.)

public static function gamepadButtonPressed(gamepad:Int, button:GamepadButton):Bool

Is the button currently down?

public static function gamepadButtonDown(gamepad:Int, button:GamepadButton):Bool

Has the button been released? (tracks press/read correctly.)

public static function gamepadButtonReleased(gamepad:Int, button:GamepadButton):Bool

Get current position of mouse.

public static function mousePosition():Vector

Has the button been pressed? (tracks unpress/read correctly.)

public static function mouseButtonPressed(button:MouseButton):Bool

Is the button currently down?

public static function mouseButtonDown(button:MouseButton):Bool

Has the button been released? (tracks press/read correctly.)

public static function mouseButtonReleased(button:MouseButton):Bool

Is the button currently up?

public static function mouseButtonUp(button:MouseButton):Bool
sound (7)

Load a sound from a file in cart.

public static function loadSound(filename:String):Sound

Play a sound.

public static function playSound(sound:Sound, loop:Bool):Void

Stop a sound.

public static function stopSound(sound:Sound):Void

Unload a sound.

public static function unloadSound(sound:Sound):Void

Speak some text and return a sound. Set things to 0 for defaults.

public static function ttsSound(text:String, phonetic:Bool, pitch:Int, speed:Int, throat:Int, mouth:Int, sing:Bool):Sound

Create Sfx sound.

public static function sfxSound(params:SfxParams):Sound

Create Sfx parameters.

public static function sfxGenerate(type:SfxPresetType):SfxParams
tile (38)

Load a tilemap (a Tiled map, exported as JSON) from a file in cart.

public static function loadTilemap(filename:String):Tilemap

Unload a tilemap.

public static function unloadTilemap(tilemap:Tilemap):Void

Update a tilemap's animation timers (deltaTime is in seconds).

public static function tileUpdate(tilemap:Tilemap, deltaTime:Single):Void

Get the size of a tilemap, in tiles.

public static function tileMapSize(tilemap:Tilemap):Dimensions

Get the size of a single tile of a tilemap, in pixels.

public static function tileTileSize(tilemap:Tilemap):Dimensions

Get a custom property of a tilemap, by name (PROP_NONE when there is no such property.)

public static function tileMapProp(tilemap:Tilemap, name:String):TilemapProp

Get the number of custom properties on a tilemap.

public static function tileMapPropCount(tilemap:Tilemap):Int

Get a custom property of a tilemap, by index (PROP_NONE when out of range.)

public static function tileMapPropAt(tilemap:Tilemap, index:Int):TilemapProp

Draw a tilemap on the screen.

public static function tileDraw(tilemap:Tilemap, posX:Int, posY:Int):Void

Draw a tilemap on the screen, tinted by a color.

public static function tileDrawTint(tilemap:Tilemap, posX:Int, posY:Int, tint:Color):Void

Draw a tilemap on an image.

public static function tileDrawOnImage(dst:Image, tilemap:Tilemap, posX:Int, posY:Int):Void

Render a whole tilemap to a new image.

public static function tilemapImage(tilemap:Tilemap):Image

Get the number of layers in a tilemap. Layers are numbered depth-first, so the children of a group layer have their own indexes too.

public static function tileLayerCount(tilemap:Tilemap):Int

Get the index of a layer of a tilemap, by name (-1 when there is no such layer.)

public static function tileLayerIndex(tilemap:Tilemap, name:String):Int

Get the name of a layer of a tilemap.

static function _tileLayerName(tilemap:Tilemap, layer:Int):hl.Bytes

Get the kind of a layer of a tilemap.

public static function tileLayerType(tilemap:Tilemap, layer:Int):TileLayerKind

Get the size of a layer of a tilemap, in tiles.

public static function tileLayerSize(tilemap:Tilemap, layer:Int):Dimensions

Get whether a layer of a tilemap is visible. Drawing a layer that Tiled marked hidden draws nothing.

public static function tileLayerVisible(tilemap:Tilemap, layer:Int):Bool

Get a custom property of a layer of a tilemap, by name (PROP_NONE when there is no such property.)

public static function tileLayerProp(tilemap:Tilemap, layer:Int, name:String):TilemapProp

Get the number of custom properties on a layer of a tilemap.

public static function tileLayerPropCount(tilemap:Tilemap, layer:Int):Int

Get a custom property of a layer of a tilemap, by index (PROP_NONE when out of range.)

public static function tileLayerPropAt(tilemap:Tilemap, layer:Int, index:Int):TilemapProp

Draw a single layer of a tilemap on the screen.

public static function tileDrawLayer(tilemap:Tilemap, layer:Int, posX:Int, posY:Int):Void

Draw a single layer of a tilemap on the screen, tinted by a color.

public static function tileDrawLayerTint(tilemap:Tilemap, layer:Int, posX:Int, posY:Int, tint:Color):Void

Draw a single layer of a tilemap on an image.

public static function tileDrawLayerOnImage(dst:Image, tilemap:Tilemap, layer:Int, posX:Int, posY:Int):Void

Render a single layer of a tilemap to a new image.

public static function tileLayerImage(tilemap:Tilemap, layer:Int):Image

Get the gid of the tile at a column/row in a tilemap layer.

public static function tileGetTile(tilemap:Tilemap, layer:Int, column:Int, row:Int):Int

Set the gid of the tile at a column/row in a tilemap layer. Swapping a gid is how a cart keeps changing state in the map itself.

public static function tileSetTile(tilemap:Tilemap, layer:Int, column:Int, row:Int, gid:Int):Void

Draw a single tile from a tilemap on the screen.

public static function tileDrawTile(tilemap:Tilemap, gid:Int, posX:Int, posY:Int):Void

Get a copy of the image of a single tile in a tilemap.

public static function tileImage(tilemap:Tilemap, gid:Int):Image

Get a custom property of a tile of a tilemap, by name (PROP_NONE when there is no such property.) These come from the tileset, so every tile with this gid shares them.

public static function tileGidProp(tilemap:Tilemap, gid:Int, name:String):TilemapProp

Get the number of custom properties on a tile of a tilemap.

public static function tileGidPropCount(tilemap:Tilemap, gid:Int):Int

Get a custom property of a tile of a tilemap, by index (PROP_NONE when out of range.)

public static function tileGidPropAt(tilemap:Tilemap, gid:Int, index:Int):TilemapProp

Get the number of objects on an object-layer of a tilemap.

public static function tileObjectCount(tilemap:Tilemap, layer:Int):Int

Get an object from an object-layer of a tilemap.

public static function tileObject(tilemap:Tilemap, layer:Int, index:Int):TilemapObject

Get the index of an object on an object-layer of a tilemap, by name (-1 when there is no such object.)

public static function tileObjectIndex(tilemap:Tilemap, layer:Int, name:String):Int

Get a custom property of an object of a tilemap, by name (PROP_NONE when there is no such property.)

public static function tileObjectProp(tilemap:Tilemap, layer:Int, index:Int, name:String):TilemapProp

Get the number of custom properties on an object of a tilemap.

public static function tileObjectPropCount(tilemap:Tilemap, layer:Int, index:Int):Int

Get a custom property of an object of a tilemap, by index (PROP_NONE when out of range.)

public static function tileObjectPropAt(tilemap:Tilemap, layer:Int, index:Int, propIndex:Int):TilemapProp
utilities (5)

Get system-time (ms) since unix epoch.

public static function currentTime():hl.I64

Get the change in time (seconds) since the last update run.

public static function deltaTime():Single

Get a random integer between 2 numbers.

public static function randomInt(min:Int, max:Int):Int

Get the random-seed.

public static function randomSeedGet():hl.I64

Set the random-seed.

public static function randomSeedSet(seed:hl.I64):Void