Building an in-game level editor (Flutter)
level-editorflutterundocanvasmobile-uxautosave
Architecture and UX lessons from Run's level editor (Flutter, 2026-03 to 2026-10), which grew to platforms, zones, items, portals, keys/locks, hazards, abilities, liquids, wind, multiple "dimensions", tilesets and themes.
Architecture
- Build the editor as a plain Flutter screen, not inside the game engine: it needs
toolbars, panels and dialogs, not physics. A
CustomPaintercanvas plus pointer handling; test-play launches the real game with the edited level. - Coordinates: canvas size equals the level size; convert screen to level with
MatrixUtils.transformPoint(invertedMatrix, screenPos). - Grid snap 32 px for structure; rect tools snap inside the cell under the cursor (not the nearest intersection); single click places one tile; shift-drag paints.
- Storage: files on Android, prefs on web; JSON with a
versionfield from day one. - Number-row keys (not numpad) select tools; give every shortcut a tooltip label.
Undo/redo
- Snapshot undo (deep copy of the level per action, 50-step cap, redo cleared on a new action) is simple and reliable at this scale; the command pattern was not needed.
- Push the snapshot BEFORE mutating. Run's properties panel called
pushUndo()insideonChanged, after the change, so the first Ctrl+Z did nothing. Capture a baseline on pointer-down around the panel and push it on the first change of an interaction; coalesce later changes. - For drags, push on the first actual movement (a
dragMovedflag), which also stops plain clicks from creating spurious undo entries.
Autosave and drafts
- Debounced autosave (3 s) plus Ctrl+S.
- Decide "changed" by content, not by events: fingerprint the serialized level minus its timestamp and compare with the last saved fingerprint. Run used to re-stamp and re-save every draft on editor exit, so a stale device would clobber newer server copies.
- Never auto-delete a draft as "empty untitled" unless every entity list is empty; a check that forgot newer lists deleted real work.
Themes over per-object styling
Run's editor is theme-first: a theme picker at the top decides the skins of every placed item,
a re-theme action converts selections, and the player skin is a per-dimension setting.
Per-object skin dropdowns were removed as confusing leftovers; data keeps a legacy skinName
for compatibility only. See Theme and skin systems for 2D games.
Keyboard
CallbackShortcuts + Focus(autofocus: true); restore focus after every dialog; make sure
shortcuts do not fire while typing in a text field. Details: Keyboard shortcuts and focus in Flutter.
Canvas pan/zoom math
Do pan and zoom in screen space (pre-multiply the transform). Pinch-pan was double-counted
until panBy/zoomAbout became pure static functions with unit tests. Anchor zoom at the
pinch focal point.
Mobile editor UX (Procreate / Figma / Mario Maker / Geometry Dash patterns)
- One finger = tool, two fingers = always pan/zoom, regardless of tool; keep "multi-touch" mode until all fingers lift so a pinch never places objects. No dedicated pan tool needed.
- Double-tap zoom-to-fit; long-press context menu (delete, duplicate, properties).
- 25+ tools in a horizontal strip is bad UX; use 5-6 categories opening sub-panels, a recent tools row (Mario Maker), and auto-hide the toolbar while editing.
- Properties as a bottom sheet in landscape (sidebars eat width); snap-to-grid on by default; prominent undo/redo (touch is imprecise); toolbars must capture their own gestures.
- Fullscreen: PWA
display: fullscreenhides all browser chrome; the Fullscreen API works in browsers;SystemChrome.immersiveStickyis native Android only. - Mario Maker requires clearing your own level before sharing it; worth copying.
- In practice Run kept the editor desktop-only on phones ("editor on desktop" note) and put the effort into the play experience.
Other lessons
- Editor canvas, runtime, and thumbnails were three separate renderers; the editor ignored radius, gradient and opacity, so it was not WYSIWYG. Share painters.
- Importing a level by reverse-engineering the runtime objects was lossy; copy the source data instead, and refuse imports of editor-locked levels.
- Every tool needs a plain-click path; Run's toxic-waste tool only worked with shift-paint.
- Hit-test entities by their real shape (a puddle as its rectangle, not a 14 px point).
- Hand-drawn thumbnails do not scale; generate them from level geometry.