- 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 mygameThe 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.hxcallbacks
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):ColorFade a color.
public static function colorFade(color:Color, alpha:Single):ColorChange the brightness of a color.
public static function colorBrightness(color:Color, factor:Single):ColorInvert a color.
public static function colorInvert(color:Color):ColorBlend 2 colors together.
public static function colorAlphaBlend(dst:Color, src:Color):ColorChange contrast of a color.
public static function colorContrast(color:Color, contrast:Single):ColorInterpolate colors.
public static function colorBilinearInterpolate(color00:Color, color01:Color, color10:Color, color11:Color, coordinateX:Single, coordinateY:Single):Colorgraphics (75)
Create a new blank image.
public static function newImage(width:Int, height:Int, color:Color):ImageCopy an image to a new image.
public static function imageCopy(image:Image):ImageCreate an image from a region of another image.
public static function imageSubimage(image:Image, x:Int, y:Int, width:Int, height:Int):ImageClear the screen.
public static function clear(color:Color):VoidDraw a single pixel on the screen.
public static function drawPoint(x:Int, y:Int, color:Color):VoidDraw a line on the screen.
public static function drawLine(startPosX:Int, startPosY:Int, endPosX:Int, endPosY:Int, color:Color):VoidDraw a filled rectangle on the screen.
public static function drawRectangle(posX:Int, posY:Int, width:Int, height:Int, color:Color):VoidDraw a filled triangle on the screen.
public static function drawTriangle(x1:Int, y1:Int, x2:Int, y2:Int, x3:Int, y3:Int, color:Color):VoidDraw a filled ellipse on the screen.
public static function drawEllipse(centerX:Int, centerY:Int, radiusX:Int, radiusY:Int, color:Color):VoidDraw a filled circle on the screen.
public static function drawCircle(centerX:Int, centerY:Int, radius:Int, color:Color):VoidDraw a filled polygon on the screen.
static function _drawPolygon(points:Array<Vector>, color:Color):VoidDraw a filled arc on the screen.
public static function drawArc(centerX:Int, centerY:Int, radius:Single, startAngle:Single, endAngle:Single, segments:Int, color:Color):VoidDraw a filled round-rectangle on the screen.
public static function drawRectangleRounded(x:Int, y:Int, width:Int, height:Int, cornerRadius:Int, color:Color):VoidDraw an image on the screen.
public static function drawImage(src:Image, posX:Int, posY:Int):VoidDraw a tinted image on the screen.
public static function drawImageTint(src:Image, posX:Int, posY:Int, tint:Color):VoidDraw an image, rotated, on the screen.
public static function drawImageRotated(src:Image, posX:Int, posY:Int, degrees:Single, offsetX:Single, offsetY:Single, filter:ImageFilter):VoidDraw an image, flipped, on the screen.
public static function drawImageFlipped(src:Image, posX:Int, posY:Int, flipHorizontal:Bool, flipVertical:Bool, flipDiagonal:Bool):VoidDraw 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):VoidDraw some text on the screen.
public static function drawText(font:Font, text:String, posX:Int, posY:Int, color:Color):VoidSave an image to persistant storage.
public static function saveImage(image:Image, filename:String):VoidLoad an image from a file in cart.
public static function loadImage(filename:String):ImageResize an image, return copy.
public static function imageResize(image:Image, newWidth:Int, newHeight:Int, filter:ImageFilter):ImageScale an image, return copy.
public static function imageScale(image:Image, scaleX:Single, scaleY:Single, filter:ImageFilter):ImageReplace a color in an image, in-place.
public static function imageColorReplace(image:Image, color:Color, replace:Color):VoidTint a color in an image, in-place.
public static function imageColorTint(image:Image, color:Color):VoidFade a color in an image, in-place.
public static function imageColorFade(image:Image, alpha:Single):VoidCopy a font to a new font.
public static function fontCopy(font:Font):FontScale a font, return a new font.
public static function fontScale(font:Font, scaleX:Single, scaleY:Single, filter:ImageFilter):FontLoad a BMF font from a file in cart.
public static function loadFontBmf(filename:String, characters:String):FontLoad a BMF font from an image.
public static function loadFontBmfFromImage(image:Image, characters:String):FontMeasure the size of some text.
static function _measureText(font:Font, text:String, textLength:Int):DimensionsMeaure an image (use 0 for screen).
public static function measureImage(image:Image):DimensionsLoad a TTY font from a file in cart.
public static function loadFontTty(filename:String, glyphWidth:Int, glyphHeight:Int, characters:String):FontLoad a TTY font from an image.
public static function loadFontTtyFromImage(image:Image, glyphWidth:Int, glyphHeight:Int, characters:String):FontLoad a TTF font from a file in cart.
public static function loadFontTtf(filename:String, fontSize:Int):FontInvert the colors in an image, in-place.
public static function imageColorInvert(image:Image):VoidCalculate a rectangle representing the available alpha border in an image.
public static function imageAlphaBorder(image:Image, threshold:Single):RectangleCrop an image, in-place.
public static function imageCrop(image:Image, x:Int, y:Int, width:Int, height:Int):VoidCrop an image based on the alpha border, in-place.
public static function imageAlphaCrop(image:Image, threshold:Single):VoidAdjust the brightness of an image, in-place.
public static function imageColorBrightness(image:Image, factor:Single):VoidFlip an image, in-place.
public static function imageFlip(image:Image, horizontal:Bool, vertical:Bool):VoidChange the contrast of an image, in-place.
public static function imageColorContrast(image:Image, contrast:Single):VoidUse an image as an alpha-mask on another image.
public static function imageAlphaMask(image:Image, alphaMask:Image, posX:Int, posY:Int):VoidCreate a new image, rotating another image.
public static function imageRotate(image:Image, degrees:Single, filter:ImageFilter):ImageCreate a new image of a gradient.
public static function imageGradient(width:Int, height:Int, topLeft:Color, topRight:Color, bottomLeft:Color, bottomRight:Color):ImageUnload an image.
public static function unloadImage(image:Image):VoidUnload a font.
public static function unloadFont(font:Font):VoidClear an image.
public static function clearImage(destination:Image, color:Color):VoidDraw a single pixel on an image.
public static function drawPointOnImage(destination:Image, x:Int, y:Int, color:Color):VoidDraw a line on an image.
public static function drawLineOnImage(destination:Image, startPosX:Int, startPosY:Int, endPosX:Int, endPosY:Int, color:Color):VoidDraw a filled rectangle on an image.
public static function drawRectangleOnImage(destination:Image, posX:Int, posY:Int, width:Int, height:Int, color:Color):VoidDraw 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):VoidDraw a filled ellipse on an image.
public static function drawEllipseOnImage(destination:Image, centerX:Int, centerY:Int, radiusX:Int, radiusY:Int, color:Color):VoidDraw a circle on an image.
public static function drawCircleOnImage(destination:Image, centerX:Int, centerY:Int, radius:Int, color:Color):VoidDraw a filled polygon on an image.
static function _drawPolygonOnImage(destination:Image, points:Array<Vector>, color:Color):VoidDraw 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):VoidDraw an image on an image.
public static function drawImageOnImage(destination:Image, src:Image, posX:Int, posY:Int):VoidDraw a tinted image on an image.
public static function drawImageTintOnImage(destination:Image, src:Image, posX:Int, posY:Int, tint:Color):VoidDraw 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):VoidDraw an image, flipped, on an image.
public static function drawImageFlippedOnImage(destination:Image, src:Image, posX:Int, posY:Int, flipHorizontal:Bool, flipVertical:Bool, flipDiagonal:Bool):VoidDraw 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):VoidDraw some text on an image.
public static function drawTextOnImage(destination:Image, font:Font, text:String, posX:Int, posY:Int, color:Color):VoidDraw a outlined (with thickness) rectangle on the screen.
public static function drawRectangleOutline(posX:Int, posY:Int, width:Int, height:Int, thickness:Int, color:Color):VoidDraw 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):VoidDraw a outlined (with thickness) ellipse on the screen.
public static function drawEllipseOutline(centerX:Int, centerY:Int, radiusX:Int, radiusY:Int, thickness:Int, color:Color):VoidDraw a outlined (with thickness) circle on the screen.
public static function drawCircleOutline(centerX:Int, centerY:Int, radius:Int, thickness:Int, color:Color):VoidDraw a outlined (with thickness) polygon on the screen.
static function _drawPolygonOutline(points:Array<Vector>, thickness:Int, color:Color):VoidDraw 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):VoidDraw 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):VoidDraw 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):VoidDraw 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):VoidDraw 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):VoidDraw a outlined (with thickness) circle on an image.
public static function drawCircleOutlineOnImage(destination:Image, centerX:Int, centerY:Int, radius:Int, thickness:Int, color:Color):VoidDraw a outlined (with thickness) polygon on an image.
static function _drawPolygonOutlineOnImage(destination:Image, points:Array<Vector>, thickness:Int, color:Color):VoidDraw 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):Voidgui (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):BoolEnd the current GUI window.
public static function guiEndWindow():VoidA static text label.
public static function guiLabel(text:String):VoidA block of wrapping text.
public static function guiText(text:String):VoidA checkbox. Returns the (possibly changed) state.
public static function guiCheckbox(label:String, state:Bool):BoolA slider. Returns the (possibly changed) value.
public static function guiSlider(value:Single, low:Single, high:Single):SingleSet the current layout row - the column widths (negative for flexible), and the row height.
static function _guiLayoutRow(widths:Array<Int>, height:Int):VoidFinish building the GUI for this frame. Called automatically at the end of update if you do not call it.
public static function guiEnd():VoidDraw the GUI to an image (0 is the screen).
public static function guiDraw(dst:Image):Voidinput (12)
Has the key been pressed? (tracks unpress/read correctly.)
public static function keyPressed(key:Key):BoolIs the key currently down?
public static function keyDown(key:Key):BoolHas the key been released? (tracks press/read correctly.)
public static function keyReleased(key:Key):BoolIs the key currently up?
public static function keyUp(key:Key):BoolGet current position of mouse.
public static function mousePosition():Vectorsound (7)
Load a sound from a file in cart.
public static function loadSound(filename:String):SoundPlay a sound.
public static function playSound(sound:Sound, loop:Bool):VoidStop a sound.
public static function stopSound(sound:Sound):VoidUnload a sound.
public static function unloadSound(sound:Sound):VoidSpeak 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):SoundCreate Sfx sound.
public static function sfxSound(params:SfxParams):SoundCreate Sfx parameters.
public static function sfxGenerate(type:SfxPresetType):SfxParamstile (38)
Load a tilemap (a Tiled map, exported as JSON) from a file in cart.
public static function loadTilemap(filename:String):TilemapUnload a tilemap.
public static function unloadTilemap(tilemap:Tilemap):VoidUpdate a tilemap's animation timers (deltaTime is in seconds).
public static function tileUpdate(tilemap:Tilemap, deltaTime:Single):VoidGet the size of a tilemap, in tiles.
public static function tileMapSize(tilemap:Tilemap):DimensionsGet the size of a single tile of a tilemap, in pixels.
public static function tileTileSize(tilemap:Tilemap):DimensionsGet a custom property of a tilemap, by name (PROP_NONE when there is no such property.)
public static function tileMapProp(tilemap:Tilemap, name:String):TilemapPropGet the number of custom properties on a tilemap.
public static function tileMapPropCount(tilemap:Tilemap):IntGet a custom property of a tilemap, by index (PROP_NONE when out of range.)
public static function tileMapPropAt(tilemap:Tilemap, index:Int):TilemapPropDraw a tilemap on the screen.
public static function tileDraw(tilemap:Tilemap, posX:Int, posY:Int):VoidDraw a tilemap on the screen, tinted by a color.
public static function tileDrawTint(tilemap:Tilemap, posX:Int, posY:Int, tint:Color):VoidDraw a tilemap on an image.
public static function tileDrawOnImage(dst:Image, tilemap:Tilemap, posX:Int, posY:Int):VoidRender a whole tilemap to a new image.
public static function tilemapImage(tilemap:Tilemap):ImageGet 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):IntGet 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):IntGet the name of a layer of a tilemap.
static function _tileLayerName(tilemap:Tilemap, layer:Int):hl.BytesGet the kind of a layer of a tilemap.
public static function tileLayerType(tilemap:Tilemap, layer:Int):TileLayerKindGet the size of a layer of a tilemap, in tiles.
public static function tileLayerSize(tilemap:Tilemap, layer:Int):DimensionsGet 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):BoolGet 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):TilemapPropGet the number of custom properties on a layer of a tilemap.
public static function tileLayerPropCount(tilemap:Tilemap, layer:Int):IntGet 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):TilemapPropDraw a single layer of a tilemap on the screen.
public static function tileDrawLayer(tilemap:Tilemap, layer:Int, posX:Int, posY:Int):VoidDraw 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):VoidDraw a single layer of a tilemap on an image.
public static function tileDrawLayerOnImage(dst:Image, tilemap:Tilemap, layer:Int, posX:Int, posY:Int):VoidRender a single layer of a tilemap to a new image.
public static function tileLayerImage(tilemap:Tilemap, layer:Int):ImageGet 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):IntSet 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):VoidDraw a single tile from a tilemap on the screen.
public static function tileDrawTile(tilemap:Tilemap, gid:Int, posX:Int, posY:Int):VoidGet a copy of the image of a single tile in a tilemap.
public static function tileImage(tilemap:Tilemap, gid:Int):ImageGet 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):TilemapPropGet the number of custom properties on a tile of a tilemap.
public static function tileGidPropCount(tilemap:Tilemap, gid:Int):IntGet 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):TilemapPropGet the number of objects on an object-layer of a tilemap.
public static function tileObjectCount(tilemap:Tilemap, layer:Int):IntGet an object from an object-layer of a tilemap.
public static function tileObject(tilemap:Tilemap, layer:Int, index:Int):TilemapObjectGet 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):IntGet 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):TilemapPropGet the number of custom properties on an object of a tilemap.
public static function tileObjectPropCount(tilemap:Tilemap, layer:Int, index:Int):IntGet 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):TilemapProputilities (5)
Get system-time (ms) since unix epoch.
public static function currentTime():hl.I64Get the change in time (seconds) since the last update run.
public static function deltaTime():SingleGet a random integer between 2 numbers.
public static function randomInt(min:Int, max:Int):IntGet the random-seed.
public static function randomSeedGet():hl.I64Set the random-seed.
public static function randomSeedSet(seed:hl.I64):Void