All articles

Advanced

Build Climbable Ropes, Chains, and Vines in SpriteKit

Jump onto a straight swinging rope, climb it, and release into a second rope that bends and stretches across six connected pieces.

The Desert Ruins sample includes both obstacles, their editable LevelEditor workspace, and the Swift code that lets the hero cross the gap. Run the sample and reach the wider gap beyond the spikes. Jump toward a rope to grab it, use Up or Down to climb, and press Jump to release.

Run and edit Desert Ruins

The Desert Ruins hero hangs from the curved second rope, with the straight first rope visible to the left.
The straight rope is on the left. The hero is hanging from the six-link rope on the right.

Set up the straight pendulum

Open the Desert Ruins workspace and level in LevelEditor. The first placement uses crossing_rope from Assets/ObstacleList.plist. Its single sprite has a top-center anchor of {0.5,1}, and the placement puts that anchor above the visible playfield.

  1. In the obstacle catalog, set allowHeroAttach to true and add climbable.
  2. Set the top and bottom of the grip area in sprite-local points. The sample uses (0, -171) and (0, -332), leaving a stretch of artwork above the climbable area.
  3. Use Rotation properties to set a repeating pendulum swing. The sample sweeps 23 degrees over 1.55 seconds, then reverses.

Select the placement and expand Climbable span to override the base span or grab radius for that spot in the level.

Build the rope that bends

Use segmented_crossing_rope as the example for a flexible rope, chain, or vine. Its root marks the fixed anchor, and its child siblings are listed in order from the anchor to the free end.

  1. In Object Editor, add child siblings with their artwork and size. Desert Ruins uses six 57-point pieces. Leave connections absent for top-center and bottom-center joints, or supply a normalized pair for each piece in the same order.
  2. Add segmentedMotion. The sample sets maximum stretch to 0.045, stiffness to 5 Hz, and damping to 0.18. Use zero stretch for chain links that pivot independently at a fixed length.
  3. Use the rotation value to set the initial lean. SpriteKit physics drives the motion from there. The Segmented motion Inspector section lets you override the base settings for one placement.

For a segmented obstacle, use negative endpoint Y values to describe resting distances down the rope. As the links move, Scroller2d finds the grip along the bending path and keeps the hero aligned after physics. The canvas shows the authored starting pose. Run the game to see the swing and stretch.

Connect the hero controls in Swift

In GameScene.swift, collect the climbable spans from the assembled obstacles and create one ClimbableAttachmentController for the hero. A hand offset positions the grip above the hero’s center. Run the controller from the scene delegate’s didEvaluateSceneActions() hook, after SpriteKit evaluates actions and before it simulates physics.

if climber.isAttached {
    let boost = jumpRequested ? CGVector(dx: facing * 235, dy: 480) : nil
    climber.update(climbAxis: climbAxis, jumpBoost: boost,
                   in: self, at: clock, deltaTime: frameDelta)
} else if !grounded {
    climber.grabNearest(among: climbableSpans, in: self, at: clock)
}

This excerpt uses one controller for both rope types. The climb axis is -1 for Up, 0 to hang, and 1 for Down. Desert Ruins uses the controller’s onEvent callback to show climb controls on grab and switch to airborne movement on release. The release event reports the grip velocity and the final launch velocity. Preserve that launch in your air controls so the hero carries the swing’s momentum toward the next rope. Reset the controller before moving the hero to a checkpoint.

Tune the crossing one change at a time

Move the second anchor or change its grab radius in LevelEditor. Save, run the sample’s sync-level.sh script, and build again. Try the transfer from a low grip and a higher one, then miss a grab on purpose and confirm the beacon respawn. This makes it easy to tell whether a harder jump came from your level layout, rope motion, or release timing.

Build the flexible bridge after the rope crossing

See how the SpriteKit scene lifecycle fits together

Where Scroller2d saves work

A custom SpriteKit controller needs to find a grip, place the hero as the rope moves, and calculate the release velocity. Scroller2d’s attachment controller shares those rules across straight and segmented ropes and reports their grab, release, and detach events. Changing the authored span or swing lets you tune a crossing while reusing the same controller. Your game maps input and chooses the jump boost.