Game UI

Export for a game engine

A game engine takes an interface as pictures: one file for each button, panel and icon, often at several sizes, and for anything that stretches, the numbers that say where it may be cut. Nox writes all of that in one pass: PNG, WebP or JPEG at 1×, 2× and 3×, pictures with room for their shadows, and a small .json beside each with its cuts.

The export sheet: three scales, room for shadows, and a slice file
The export sheet: three scales, room for shadows, and a slice file

Choose a format#

FormatUse it forWhat to know
PNGSprites, buttons, panels, iconsLossless, transparent wherever the node covers nothing. The safe choice for every engine
WebPThe same, where the engine reads itLossless by default and smaller than PNG. Lossy with a quality from 1 to 100 when size matters more
JPEGOpaque backdrops and large painted screensSmaller, no transparency. Quality 90 unless you say otherwise. What the node does not cover is white

Use PNG or lossless WebP for anything with a hard edge or a transparent corner. Lossy pictures show their loss first along the edges of flat art.

Choose the scales#

A scale is pixels to a unit. A 200 × 64 button is 200 × 64 pixels at 1×, 400 × 128 at 2× and 600 × 192 at 3×. Choose several at once and Nox writes a file for each:

Buy.png
[email protected]
[email protected]

A file is named after its node. The larger scales are marked @2x and @3x. Two nodes with the same name get a number, as Buy 2.png, so name every node you export.

  • A game with one interface size, such as a 1080p console game, needs only 1× from a 1920 × 1080 design.
  • A game that also runs at 4K needs 2×.
  • A phone game designed in points needs 2× and 3×.

Room for shadows#

A picture is cut at its node's box. A drop shadow, the soft shadow of Lighting & Depth, or a layer blur lies outside that box, and would be cut off.

Turn on Room for shadows and each picture grows to hold everything its node draws. The room is rounded up to whole units, so every scale lands on whole pixels.

A 200 × 64 button exported with room: the picture is 296 × 160
A 200 × 64 button exported with room: the picture is 296 × 160

The picture is now larger than the button, and the engine must know where the button is inside it. That is what the slice file is for.

The slice file#

Turn on Slice file (.json) beside each and a <name>.json is written beside each node's pictures. This is the file for the button above, a 200 × 64 rectangle with cuts of 24 on every side:

{
  "content": { "height": 64, "width": 200, "x": 48, "y": 38 },
  "files": [
    { "name": "Buy.png", "scale": 1 },
    { "name": "[email protected]", "scale": 2 },
    { "name": "[email protected]", "scale": 3 }
  ],
  "name": "Buy",
  "padding": { "bottom": 58, "left": 48, "right": 48, "top": 38 },
  "size": [296, 160],
  "slice": { "bottom": 82, "left": 72, "right": 72, "tiled": false, "top": 62 }
}
FieldWhat it is
sizeThe picture's width and height at scale 1
contentWhere the node's own box lies in the picture. Place the picture so that this box lands where the design has the button
paddingThe room on each side, from Room for shadows. All 0 without it
sliceThe node's nine-slice cuts, measured in this picture: its own cuts with each side's padding added. Here 24 + 48 is 72 at the left. tiled is true where the node is set to Tile
filesEach picture written, with its scale

All numbers are at scale 1. Multiply by the scale of the file you load: the left cut of [email protected] is 144 pixels.

In the engine, set the sprite's nine-slice border from slice, and offset the sprite by content.x and content.y. A button stretched this way keeps its round corners and its whole shadow at any width.

Note

Set the cuts in the design before you export, on a picture, a frame or a plain shape. The file of a node with no cuts has no slice at all. See Nine-slice.

Export#

By hand
  1. Select what to export: one node, several, or nothing to get the frames of the page.
  2. Choose File › Export… (⇧⌘E), or press Export… at the foot of the inspector.
  3. Choose the Format. For WebP, choose Lossless or Lossy and set the quality with the slider.
  4. Press each Scale you want: 1×, 2×, 3×. Several can be lit at once.
  5. Untick anything in the list you do not want.
  6. Turn on Room for shadows and Slice file (.json) beside each.
  7. Press the button, which says how many files it will write, and choose a folder.

The two switches are dimmed for SVG and PDF: they are for pictures.

With an agent

Name the nodes, the folder and the scales. The tool is export_assets. It writes every file or none, and it does not replace a file that is already there unless you say so.

Export the Buy button and the dialog panel for the engine: PNG at 1×, 2× and 3×,
with room for shadows and slice files, into /Users/you/game/assets/ui.

The agent calls export_assets with:

{
  "ids": ["4:8", "4:12"],
  "folder": "/Users/you/game/assets/ui",
  "format": "png",
  "scales": [1, 2, 3],
  "effects": true,
  "metadata": true,
  "overwrite": true
}

effects is Room for shadows. metadata is the slice file. The reply lists each file with its node, path, scale, size in pixels and bytes, and the content of each slice file.

For lossy WebP the agent adds a quality: "format": "webp", "quality": 90. Leave quality out and the WebP is lossless.

What to export#

Export the parts, not the screen. The engine draws the HUD from pieces it can move, stretch and animate.

  • Each panel and button once, at its smallest useful size, with its cuts. The engine stretches it.
  • Each state of a button as its own picture. Rename the variants first so the files say which is which: see Button states.
  • Each icon on its own, at every scale.
  • Not the text. Scores, names and labels are drawn by the engine in the game's font, so they can change and be translated. Hide the label, or export the plate under it.
  • Not the level art that stood in for the game.

To export a layer that sits inside an instance, such as the icon in a button, double-click into the instance to select the layer, then export. Only that layer is written, with nothing of what lies behind or beside it.

Check the result#

  • Open a 1× picture and count: its size should match size in the slice file.
  • Look at the edge of a shadow. A shadow that ends in a hard line was exported without room.
  • Load the 3× file on the largest screen you ship for, at 100%. Soft edges there mean the art was drawn off whole units.
  • Keep the .ndf file beside the assets in the project. An agent can export again with one call whenever the design changes.