← All templates
Top-down explorer
IntermediateTemplateWeb & desktopMobile friendly

Top-down explorer

Game · Adventure

Walk around outside and step through the door into the house. The hero faces and animates the way it walks, up, down, left or right, all from a state graph with no animation code. Two screens, joined by doors.

by Arcadia Studio
Read the guide ↓

Top-down explorer

A little top-down world. Walk around outside, then step up to the front door and you're inside the house. Walk out through the doorway at the bottom and you're back outside.

The best part is the hero: it faces the way it walks and plays a walking animation for each direction, then stands still facing the same way when you stop. That's all done by a state graph, with no animation code at all.

Outside

What you'll learn

  • Making an 8-clip sprite: walking and standing, for each of four directions.
  • Building a state graph that chooses the right clip from the keys being held.
  • Moving a character with the Top-down mover component.
  • Making scenery solid with Static body, and keeping the player on screen with invisible walls.
  • Joining two screens with doors: trigger zones whose trigger_enter opens the other screen.

Glossary

WordWhat it means
SpriteA control that plays frames from a picture sheet.
ClipA named run of a sprite's frames, like walk_left (frames 4 and 5).
State graphA list of states, each playing a clip, and the ways out of each state: the conditions for switching. It runs on its own, every frame.
PriorityWhen more than one way out is true, the highest priority wins.
input:upIn a condition, true while the up input is held. !input:up means it isn't. && means "and".
Top-down moverA component that moves a control with the four direction inputs, in eight directions.
Static bodyA component that makes a control solid: it never moves, and nothing walks through it.
Trigger zoneA component for an invisible area that fires trigger_enter when something walks into it.

Rebuild it from scratch

1. Project and screens

  1. File → New project, named Top-down explorer with the Id explorer. In **Project → Project settings…, set Made for to Web & desktop only**.
  2. Make three screens, all 320 × 180: title (tick Main screen), outside and house.
  3. On title, add a Play button whose click has the actions play_sound and open_ui outside.
  4. On outside and house, open Screen settings and set Tick interval (ms) to 16 and Gravity to 0. From above, nothing falls.

2. The hero's frames and clips

  1. Draw the hero in the Pixel editor as eight 16 × 16 frames: down, down stepping, up, up stepping, left, left stepping, right, right stepping. The right frames are the left ones flipped.

The hero's eight frames

  1. Add a Sprite called hero to the outside screen, just below the house door.
  2. In the Sprite sheet editor, make eight clips:
ClipFramesSpeed
idle_down01
walk_down0, 16
idle_up21
walk_up2, 36
idle_left41
walk_left4, 56
idle_right61
walk_right6, 76

3. Walking

  1. Select the hero and + Add component → Top-down mover. It adds the inputs up, down, left and right: arrows, WASD, the d-pad, and a drag on a touch screen. It also writes scripts/client/hero_mover.js, which sets the hero's speed from those inputs every tick. Tune SPEED on its card.
  2. On the hero's Rigidbody card, choose Dynamic. A dynamic body is stopped by walls, and with the screen's gravity at 0 it doesn't fall.

4. The state graph

This is the heart of the template. Open Advanced → State graphs…, click + New graph, give it the ID hero_walk, and choose the Sprite hero. Add eight states with + State, one per clip, each playing the clip with its own name.

Every idle state has four ways out. Holding any direction starts walking that way:

From idle_down (and the same for every idle state)whenpriority
→ walk_downinput:down1
→ walk_upinput:up1
→ walk_leftinput:left1
→ walk_rightinput:right1

Every walk state has four ways out too. Here's walk_left:

From walk_leftwhenpriority
→ walk_downinput:down && !input:left2
→ walk_upinput:up && !input:left2
→ walk_rightinput:right && !input:left2
→ idle_left!input:left1

The other walk states follow the same pattern: swap left for their own direction. Set Starts in to idle_down and click Apply.

Why && !input:left? Without it, holding Left and Up together would flip between walk_left and walk_up every frame. With it, the hero keeps facing the first direction you pressed until you let go of it. The priorities make sure turning (2) is checked before stopping (1).

5. Outside

  1. Add a green Panel as grass, and a sandy Panel as a path up to the house.
  2. Draw a house (48 × 40 in the Pixel editor) and add it as an Image, drawn at double size (96 × 80). Give it + Add component → Static body.
  3. Add some trees as Images, each with a Static body.
  4. Add four Box colliders (from ▸ Advanced · web & desktop in the Toolbox) just outside the screen's edges, each a Static body. They're invisible walls that keep the hero on screen.

6. The doors

  1. Outside: add a small Box collider called door right in front of the house's door (16 × 6), and give it + Add component → Trigger zone. In its Events, on trigger_enter, add the actions play_sound (a door sound) and open_ui with the value house.
  2. Inside: build the house screen from Panels: a wooden floor, walls with Static body, a rug, a table and a bed. Leave a gap in the bottom wall. Put a Box collider called exit in the gap, as a Trigger zone, with trigger_enter → play_sound and open_ui outside.
  3. Copy the hero onto the house screen, just above the doorway. Its components and clips come with it. Add the same state graph there too.

Inside the house

7. Play

Press Preview (F5), walk around, and watch the hero turn. Walk into the door, look around the house, and walk back out.

How it works

  • Three jobs, three tools. The Top-down mover moves the hero. The state graph picks its animation. The physics engine stops it at walls. None of them knows about the others: the graph only watches the keys, and never the speed.
  • The graph remembers the direction. Stopping goes to the idle state *of the direction you were walking*, so the hero keeps facing that way. That memory is simply which state you're in.
  • Doors are just events. trigger_enter is like click: it can have actions. open_ui switches screens, so a door needs no code.
  • Each screen starts fresh. When you come back outside, the hero starts where you placed it on that screen: right by the door, which is exactly where you'd walk out.

Make it yours

  • Add more rooms: one more screen, one more door trigger, one more open_ui.
  • Put a Pickup on some coins, like in Platformer, and show them with Coins: ${score}.
  • Add a friendly character: a sprite with the Follower component that walks after the hero (set its TARGET_TAG to a tag you give the hero).
  • Ready for something bigger? The Adventure template builds a whole world of rooms on one screen, with a scrolling camera.