Load a SpriteKit Level from a Plist in Swift
Give level layout a reusable home and validate it before creating your scene.
Follow along with the downloadable Desert Ruins iOS demo. Source references in this article point to Desert Ruins iOS Demo/DesertRuins/LevelData.swift. Code excerpts use the sample’s existing types and properties.
The problem with constructing every level in Swift
A level can start as a few sprite initializers in a scene. As it grows, those initializers collect positions, sizes, images, and behavior settings. Making a second level means deciding which values to copy and which logic to share. Scroller2d gives those values a defined data model that LevelEditor can edit and the game can load.
Load the exported file
Desert Ruins bundles its level under Levels and its shared catalogs under Assets. LevelData.init() now uses LevelAssemblyHelper.Resources to load all four files. Decoding errors propagate to the caller, and a missing level index throws a descriptive error.
resources = try LevelAssemblyHelper.Resources(
levelURL: levelURL,
obstacleURL: assets.appendingPathComponent("ObstacleList.plist"),
characterURL: assets.appendingPathComponent("CharacterList.plist"),
objectURL: assets.appendingPathComponent("ObjectList.plist")
)
Keep the catalogs with the level
The helper decodes the existing SceneConfig, ObstacleConfig, and CharacterConfig formats, plus an array of GenericObject for the object catalog. Include the files and artwork in the app target. Catalog loading does not copy images or rewrite names; the demo maps editor image names to its category-prefixed asset names.
Turn the model into a playable scene
GameScene.build() passes the loaded resources to LevelAssemblyHelper.build. The API resolves catalog defaults and per-level overrides, constructs ground with CreateGroundHelper, and delegates obstacle and enemy creation to the existing SDK helpers. This minimal form uses their default creation behavior:
let assembly = try LevelAssemblyHelper.build(
resources: data.resources,
scene: self,
groundTexture: { try self.data.texture($0, in: "Ground") }
)
assembly.install(in: self)
The actual demo also passes collision masks, a two-point terrain collision inset, an obstacle configuration callback, and a custom enemy factory. Its player is built separately. Installation attaches the assembled root and applies scene settings, ground-height lookup, and level end point. Desert Ruins then explicitly selects aspectFit for its complete touch HUD.
Flat horizontal ground, repeated tiles, gaps, and continuous collision runs are supported. Sloped, stacked, and hazard ground types require a custom builder and currently throw an unsupported-configuration error. The game supplies pickups, parallax, input, combat, checkpoints, and results. CameraFollowHelper now handles following and camera bounds.
Try a controlled edit
Run the sample once. Change one coin position in LevelEditor, save the file, copy it into the bundled Levels folder, and rebuild. If the result is unchanged, inspect the resource copied into the app and confirm the loader points to it. This small check catches a stale resource before you investigate gameplay.
Where Scroller2d saves work
A single resource loader applies the same decoding and missing-level validation to each level and its supplied catalogs. The comparison below isolates loading and validating one level. Both versions use the same level model and leave node creation to later code.
Manual decoding and validation (7 lines)
let decoder = PropertyListDecoder()
let bytes = try Data(contentsOf: levelURL)
let config = try decoder.decode(SceneConfig.self, from: bytes)
guard let levels = config.levels, levels.indices.contains(levelIndex) else {
throw LevelAssemblyError.invalid("level index")
}
let level = levels[levelIndex]
With Scroller2d (2 lines)
let resources = try LevelAssemblyHelper.Resources(levelURL: levelURL, levelIndex: levelIndex)
let level = resources.level
These counts describe only the excerpts shown. They exclude surrounding setup and game logic. The manual example uses Scroller2d’s data model with Foundation’s property list decoder.