All articles

Advanced

Build Walkable Slopes, Steps, and Stacked Terrain in SpriteKit

Build collision from the top of your terrain artwork and reuse the same surface for standing, jumping, and placing props.

In Desert Ruins, cross the flexible bridge and continue up the sandstone ramp. The explorer follows the ramp to a stacked plateau, then steps down to the relic. Open the same level in LevelEditor to compare how those ground sections are configured.

Pick collision that matches the terrain

  • Rectangular ground works well for flat platforms. The top is level across the section.
  • angle samples the artwork’s opaque upper surface and builds a walkable edge chain. Use it for slopes or uneven tops.
  • texture uses the tile silhouette when collision needs the full shape, including its sides.

The sample ramp uses angle. Its plateau also uses angle, with stack enabled and sandstone_foundation,sandstone listed from bottom to top. On the descending steps, imageBottomLayer draws the foundation under the raised sandstone cap.

Share one surface between placement and movement

Desert Ruins builds the ground through LevelAssemblyHelper. Installing the result in AppSharedSceneBase makes the assembled surface available through groundSurfaceY(at:). Gravity-placed obstacles use it to find the ground at their position. The hero’s grounded check samples across the feet so it can handle seams and steps.

let left = hero.position.x - footHalfWidth
let right = hero.position.x + footHalfWidth
let support = [left, right].compactMap { groundSurfaceY(at: $0) }.max()

This is the static terrain part of the check. A nil result means there is no static surface at either sample point. A game can also check vertical speed and compare the returned height with the hero’s feet. Keep the terrain and lookup in the same coordinate space.

Test a terrain revision

Change the size of a sandstone section or adjust its collision edge offset in LevelEditor. Save, run the sample’s sync-level.sh script, and rebuild. Walk across the ramp seam, jump from the plateau, and check that gravity-placed props still sit on the same surface. The terrain definition is the place to make those changes.

Add a moving deck with the flexible rope bridge guide

Where Scroller2d saves work

A hand-built slope needs collision geometry and a height lookup that agree. Scroller2d samples the artwork, builds the walkable edges, and exposes the same surface for placement and grounding. Change a ramp tile or step offset in LevelEditor, then test seams and jumps against the same lookup.