Skip to content

willow ​

Illustration: a glowing tree of floating sprites and panels in a twilight forest, like a living scene graph

willow is ThicketScript's 2D module. It is a display tree, in the spirit of Flash and Starling: you build a tree of nodes, set each one's position, scale, rotation and colour, and willow draws the whole tree every frame. You never issue draw calls yourself.

It is built into thicket. List it under systems in thicket.json and import what you need from "willow".

A minimal program ​

json5
{
    entry: "app.tks",
    systems: ["willow"],
    window: { title: "Hello willow", width: 800, height: 600 },
}
ts
import { Quad } from "willow";

class Hello {
    static main(): void {
        const box: Quad = new Quad(120, 120, Color.hex("#4FA3E0"));
        box.setAnchor(0.5, 0.5);
        box.x = 400;
        box.y = 300;
        engine.root2d.add(box);

        App.onFrame((dt: float): void => {
            box.rotation += Math.PI * dt;
        });
    }
}

A blue square spins in the middle of the window, half a turn per second.

  • new Quad(w, h, color) makes a solid rectangle node.
  • engine.root2d is the root of the 2D tree. A node is drawn once it is in the tree.
  • App.onFrame runs once per drawn frame. dt is the frame time in seconds.

How willow fits ​

A GPU renderer forgets everything between frames: each frame, every draw has to be issued again. willow keeps a retained tree on top of it. You describe what exists (a sprite here, a label there), and each frame willow walks the tree, works out where everything is, sorts it and turns it into as few GPU draws as it can.

text
Your game      gameplay, content, rules
willow         the node tree, transforms, draw order, batching, hit testing
thicket        the window, the GPU, input, audio, the ThicketScript runtime

What willow is not:

  • Not a widget toolkit. It has no buttons, lists or layout. For those, use willowui, which is built on willow nodes.
  • Not a game framework. It does not decide how you structure entities, levels or saves. It draws your tree and routes input to it; the rest is your code.

Where to go next ​

What is in willow ​

AreaWhat you getGuide
TreeNode, the scene's world and screen roots, render layers, eventsThe scene graph
ImagesSprite, SpriteBatch, Texture, TextureRegion, Atlas, AnimationPlayerSprites and textures
TextText, Font (bundles, TTF, pixel fonts), outline, glow and shadowText and fonts
ShapesQuad, Quad.line, Polygon, Mesh, custom paintShapes and meshes
MotionTweenGroup, node tickers, Transition between screensTweens and transitions
TimeonUpdate, onTick, pause, time scale, interpolationLifecycle and time
InteractionPointer handlers, hit shapes, drag, wheel, pinch, pointer captureInput and hit testing
WorldCamera2D, TileLayer, TilemapViewport, NodeIndexCamera and layers, Tilemaps
EffectsParticles, filters, masks, lighting, render texturesEffects
AdvancedRope, DistortionGrid, physics bodiesRope and distortion, Physics

Without a window ​

A console program can list willow too. The node tree, transforms, hit shapes, events, NodeIndex, physics and text measuring work with no window or GPU, which is useful for tools, servers and tests. Loading images needs a window. See Running without a window.