Design SpriteKit Levels for Different Screen Sizes
Use scene coordinates and device properties to make layout decisions explicit.
Follow along with the downloadable Desert Ruins iOS demo. Source references in this article point to Desert Ruins iOS Demo/DesertRuins/GameScene.swift. Code excerpts use the sample’s existing types and properties.
Pixels and scene coordinates serve different jobs
A level that looks right on one simulator can feel cramped or show extra space on another. Start by deciding the logical scene size and how SpriteKit should fit it into the view. Then test how the camera, controls, and object placement behave within that choice.
Use the level’s scene settings
LevelData validates settings.size and converts it with toCGSize(). GameScene initializes its base scene with that size. Assembly installation applies the exported size, anchor point, and scale mode; the demo then explicitly selects aspectFit to keep its complete HUD visible. In Desert Ruins the level uses an 874 by 402 design space. The excerpt shows that setup inside the sample initializer.
Understand the visible result
aspectFit preserves the scene’s proportions and can leave unused space around it on a differently shaped display. The anchor point determines where the scene origin sits. Changing either affects how you interpret positions and place screen-relative UI, so make those choices before tuning a level’s jumps.
super.init(size: data.sceneSize)
scaleMode = .aspectFit
anchorPoint = data.level.settings.anchorPoint?.toCGPoint() ?? CGPoint(x: 0.5, y: 0.5)
backgroundColor = SKColor(red: 0.23, green: 0.17, blue: 0.29, alpha: 1)
Resolve device properties consistently
The model supports device-specific size, position, and offset information. LevelEditor lets you configure these variations. A game’s loader must select and apply the intended device values consistently. The assembly and ground helpers use the SDK’s device-value resolution. Catalog and placement device records merge by exact deviceName. The sample also uses the same deviceValue extension for manually created pickups and the player. Update CameraFollowHelper.viewportSize when the visible world dimensions change, including camera zoom.
Test gameplay and controls
Run on an iPhone and an iPad simulator with different aspect ratios. Check the first gap, the camera’s end stop, the HUD, and the Level End panel. Confirm that touch controls remain reachable and that a device-specific art adjustment has not changed the collision body or the intended jump distance.
Where Scroller2d saves work
Device-specific size and placement values live with the object definition. The same scene can load an iPhone and iPad layout through the same data path. Recheck important landmarks and HUD readability on both sizes while keeping device exceptions out of each object’s creation logic.