Tile menus
A DS menu screen looks like a picture, but it is not drawn as one. It is assembled from small square tiles, a handful of palettes and a few sprites, the same way the GBA and Game Boy games build theirs. Knowing how is the key to making screens that cost on the DS what the originals cost, and to matching them pixel for pixel. This page explains the parts. The hardware itself is on The 2D engines and Screens and touch; what a creator edits is on Menus and UI styles.
Screen parts
Section titled “Screen parts”Each of the DS’s two screens has its own 2D engine with up to four background layers and up to 128 sprites. A menu screen uses them like this:
| Part | Made of | Used for |
|---|---|---|
| Background art | a layer of tiles from a picture | the screen’s ground, panels, button shapes |
| Windows | rectangles of tiles on a layer, with text drawn into them | names, numbers, descriptions, lists |
| Frames | nine kinds of tile around a window | the border of every box |
| Sprites | small pictures placed anywhere, over or under layers | cursors, creature icons, item icons, anything that moves |
| Palettes | 16 colours each, 16 per layer set and 16 for sprites | every colour, and every state |
| Brightness and blending | whole-screen registers | fades to black or white, see-through panels |
Everything is 8 × 8 pixel tiles. A layer is a map: a grid of entries, each naming a tile, a palette and whether it is flipped. The picture on screen is the hardware reading that map every frame. Changing a screen means changing map entries, tiles or palettes, never redrawing pixels on the screen itself.
Windows and text
Section titled “Windows and text”A window is a rectangle of a layer whose map entries each point at a tile of their own. The program keeps those tiles’ pixels in main memory, draws text into them glyph by glyph, and sends the changed tiles to video memory. To the hardware it is just more tiles. This is why text can be any width and colour and still cost only the tiles its rectangle covers.
A text box shows two lines, types its letters one at a time at the player’s chosen speed, waits with a small bobbing arrow at the end of a page, and either moves the text up a line or wipes the box for a new paragraph. A sign uses the same mechanism with its own frame.
Frames
Section titled “Frames”A window’s border is built from a nine-slice: a corner tile for each corner, an edge tile for each side repeated along it, and a middle tile repeated to fill. Any size of box is made from the same nine tiles, so a whole game’s boxes cost a few tiles of video memory. A frame’s end caps can be wider than its rails, and the player may choose among several frame designs in the options; each is just another set of tiles.
Sprites
Section titled “Sprites”Things that move or sit over the art are sprites: the cursor around a row, creature icons that bob, a ball that rocks, an arrow that nudges at the end of a list, a held item mark. Sprites have their own tile memory and palettes, can be flipped, scaled, rotated and made translucent, and are placed by a position, not on the tile grid. Moving a cursor is changing two numbers.
Palettes
Section titled “Palettes”A selected, fainted, empty or chosen panel in a party screen is usually the same tiles under another palette. A pressed button is another palette or another few map entries. Changing a palette recolours every tile that uses it, at once, for the cost of writing a few colours. That is how a screen can show many states with very little art, and how a whole screen can be faded or tinted cheaply.
Touch areas
Section titled “Touch areas”On the lower screen, each button is a touch rectangle that does what a key does. The games check a touch in two steps where the shape matters: first whether the pen is inside the rectangle, then whether the picture under the pen is drawn there, so a round button answers only inside its circle. Touch targets are large and close together. In the generation-4 games every touch control also has a key, and the first key press only shows where the cursor is.
Behaviour
Section titled “Behaviour”Read across the games, the screens share one shape: fade in, wait for input, open a list of actions, show a message and wait, run an action, fade out with a result. They also share rules of feel worth knowing when matching one:
- Windows are instant. A box, list or menu the player asked for appears on the next frame. Time is spent on events in the world, not on opening windows.
- Everything sits on the tile grid, with frames drawn a little inside their tiles so boxes never touch.
- Something is always alive: an arrow bobs, an icon loops, a cursor breathes.
- Lists that are rings wrap; questions do not.
- Every press answers within a few frames.
PokeLoom
Section titled “PokeLoom”PokeLoom’s interface is built the same way, from the first line (plan 05). Every
window, text box, list, gauge and button is background tiles and sprites. Text is
drawn into tiles kept in memory and only changed tiles are sent on. Frames, buttons
and gauges are map entries naming tiles of the skin (graphics/ui/skin.pfk), and
the window frame can be replaced by a 24 × 24 picture of three tiles by three. A
component is a small state machine: it reads the tick’s input and sends what changed.
Nothing allocates after a component is made.
Because the 2D output follows the DS’s rules exactly, a menu on desktop is the same pixels as in melonDS, and one golden image covers both.
Styles: behaviour in code, look in data
Section titled “Styles: behaviour in code, look in data”The games’ screens differ far more in how they look than in how they work. So PokeLoom
writes each screen family’s behaviour once (what the cursor may reach, what choosing a
member does) and keeps its look as data: rectangles, cursor neighbours, palettes for
each state, timings, sounds and pictures. Today’s built-in styles are a project’s
layout files under layouts/, each naming its style and holding every number of it.
The build fits each screen’s pictures into the DS’s tiles and palettes and says when
it had to reduce colours or tiles. See Menus and UI styles.
The one UI system
Section titled “The one UI system”Planned (plan 45): a screen is a family’s logic plus a record. The logic publishes the values it offers (a name, a health bar), the states a part depends on (selected, fainted, pressed) and the actions input may ask of it. The record is a flat table of parts drawn from a closed list (text, number, gauge, icon, button, list, drag area and others), each with its place, its look per state, its cursor neighbours and its motion. One drawer and one input router run every record; the engine’s own look is just the default record.
The record is the DS’s model written down: a part is a window, a sprite, a set of map entries or a palette role. That is what lets the build check a record before it ever runs:
- a part outside its screen, or a focus no key can reach;
- an action only the pen can reach (every screen must work with keys alone);
- text that cannot fit, measured with the part’s font in every language;
- art over the DS’s tile, palette and sprite limits for that screen.
On the DS, a build links only the part kinds a game’s records name, so a game that never uses a dial or a drag area carries no code for them.
One model
Section titled “One model”A game’s menus are records and pictures. Platinum’s party screen and Emerald’s do the same things in different places with different motions; in PokeLoom they are two records of one party family. An import writes the original’s records and art into the creator’s private project, and a creator can mix families from different games, or draw their own, without writing code.