Build a Flexible Rope Bridge in SpriteKit
Connect six wooden planks across a ravine and give the hero a deck that flexes underfoot.
In Desert Ruins, the bridge comes right after the two swinging ropes. Walk onto the deck to see it sag, then jump from a plank and continue toward the Sun Relic. The sample includes the editable level, plank artwork, and Swift code.
Lay out the deck in LevelEditor
Open the Desert Ruins workspace and find Flexible rope bridge. It uses the plank_bridge entry in Assets/ObstacleList.plist. The placement origin is the near anchor. The far anchor uses obstacle-local coordinates.
- In Object Editor, add six child
siblingsin order from the near ledge to the far ledge. Each sample plank is 40 points wide and 12 points high. The default connections sit at the midpoint of each side. - In
segmentedMotion.anchors, setjointIndexto6andpositionto(238, 0). Joint zero is the obstacle origin. Six planks provide 240 points of deck for the 238-point span, leaving slack for the starting sag. - Set
isWalkableto true. The sample leaves stretch at zero and sets damping to0.25. The connections can still pivot, so the deck flexes as the hero puts weight on it.
To move the far anchor for just this placement, open Segmented motion in the Inspector, turn on Override base motion, and choose Set far anchor. The canvas marks both anchors and shows the starting sag. Try the level in the game to see how the deck responds to the hero.
Let the hero jump from the moving deck
CreateObstacleHelper builds the planks, pins the ends, and applies the obstacle’s collision masks. Desert Ruins sets the plank category to staticObjectBody and the collision mask to humanPlayer so they work with the hero’s existing terrain collision rules.
In GameScene.swift, the demo checks the bridge beneath the hero’s feet alongside static terrain. Sampling the left, center, and right of the foot area helps when the hero straddles a seam between planks.
private var onBridgeDeck: Bool {
let feet = player.position.y + playerBodyCenter.y - playerBodySize.height / 2
let halfWidth = playerBodySize.width / 2
return [-halfWidth, 0, halfWidth].contains { offset in
bridgeSurfaceY(at: player.position.x + offset, near: feet, tolerance: 9) != nil
}
}
The scene calls this check during its movement update, using the deck’s latest simulated position. Once the grounded check accepts the bridge, the ordinary Jump button works from a moving plank.
Test the crossing under load
Walk across, pause near the middle, and jump from a plank. Check that both ends meet the ledges and that the hero can step off the far end. Then shorten the anchor spacing a little or change damping in LevelEditor, save, and rerun sync-level.sh before rebuilding. Keep the span within the reach of the connected planks.
Build the swinging ropes that lead to the bridge
Where Scroller2d saves work
SpriteKit supplies physics bodies and joints. Scroller2d builds the joint chain from the authored planks and anchors, calculates its starting sag, and exposes the moving deck height. Change the span in LevelEditor and keep the same grounded check. The game still decides when a jump is allowed.