Community-maintained Agent Skills for complete Swift and Apple-platform app delivery.
73
92%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Medium
Suggest reviewing before use
Read this reference when the task needs concrete setup, API wiring, or implementation recipes. Keep scope, workflow, non-obvious invariants, mistakes, and review gates in the parent SKILL.md.
SpriteKit renders content through SKView, which presents an SKScene -- the
root node of a tree that the framework animates and renders each frame.
Subclass SKScene and override lifecycle methods. The coordinate system
origin is at the bottom-left by default.
import SpriteKit
final class GameScene: SKScene {
override func didMove(to view: SKView) {
backgroundColor = .darkGray
physicsWorld.contactDelegate = self
physicsBody = SKPhysicsBody(edgeLoopFrom: frame)
setupNodes()
}
override func update(_ currentTime: TimeInterval) {
// Called once per frame before actions are evaluated.
}
}guard let skView = view as? SKView else { return }
skView.ignoresSiblingOrder = true
let scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .resizeFill
skView.presentScene(scene)Use .resizeFill when the scene should adapt to view size changes (rotation,
multitasking). Use .aspectFill for fixed-design game scenes. .aspectFit
letterboxes; .fill stretches and may distort.
Each frame follows this order:
update(_:) -- game logicdidEvaluateActions() -- post-action logicdidSimulatePhysics() -- post-physics adjustmentsdidApplyConstraints()didFinishUpdate() -- final adjustments before renderingOverride only the callbacks where work is needed.
Use SKNode (without a visual) as an invisible container or layout group.
Child nodes inherit parent position, scale, rotation, alpha, and speed.
SKSpriteNode is the primary visual node.
| Class | Purpose |
|---|---|
SKSpriteNode | Textured image or solid color |
SKLabelNode | Text rendering |
SKShapeNode | Vector paths (expensive per draw call) |
SKEmitterNode | Particle effects |
SKCameraNode | Viewport control |
SKTileMapNode | Grid-based tiles |
SKAudioNode | Positional audio |
SKCropNode / SKEffectNode | Masking / CIFilter |
SK3DNode | Embedded SceneKit content |
let player = SKSpriteNode(imageNamed: "hero")
player.position = CGPoint(x: frame.midX, y: frame.midY)
player.name = "player"
addChild(player)Set ignoresSiblingOrder = true on SKView for better performance; SpriteKit
then uses zPosition to determine order. Without it, nodes draw in tree order.
background.zPosition = -1
player.zPosition = 0
foregroundUI.zPosition = 10Assign name to find nodes without instance variables. Use childNode(withName:),
enumerateChildNodes(withName:using:), or subscript. Patterns: // searches
the entire tree, * matches any characters, .. refers to the parent.
player.name = "player"
if let found = childNode(withName: "player") as? SKSpriteNode { /* ... */ }SKAction objects define changes applied to nodes over time. Actions are
immutable and reusable. Run with node.run(_:).
let moveUp = SKAction.moveBy(x: 0, y: 100, duration: 0.5)
let grow = SKAction.scale(to: 1.5, duration: 0.3)
let spin = SKAction.rotate(byAngle: .pi * 2, duration: 1.0)
let fadeOut = SKAction.fadeOut(withDuration: 0.3)
let remove = SKAction.removeFromParent()// Sequential: run one after another
let dropAndRemove = SKAction.sequence([
SKAction.moveBy(x: 0, y: -500, duration: 1.0),
SKAction.removeFromParent()
])
// Parallel: run simultaneously
let scaleAndFade = SKAction.group([
SKAction.scale(to: 0.0, duration: 0.3),
SKAction.fadeOut(withDuration: 0.3)
])
// Repeat
let pulse = SKAction.repeatForever(
SKAction.sequence([
SKAction.scale(to: 1.2, duration: 0.5),
SKAction.scale(to: 1.0, duration: 0.5)
])
)let walkFrames = (1...8).map { SKTexture(imageNamed: "walk_\($0)") }
let walkAction = SKAction.animate(with: walkFrames, timePerFrame: 0.1)
player.run(SKAction.repeatForever(walkAction))Control the speed curve with timingMode (.linear, .easeIn, .easeOut,
.easeInEaseOut). Assign keys to actions for later access:
let easeIn = SKAction.moveTo(x: 300, duration: 1.0)
easeIn.timingMode = .easeInEaseOut
player.run(pulse, withKey: "pulse")
player.removeAction(forKey: "pulse") // stop laterSpriteKit provides a built-in 2D physics engine. The scene's physicsWorld
manages gravity and collision detection.
// Circle body
player.physicsBody = SKPhysicsBody(circleOfRadius: player.size.width / 2)
player.physicsBody?.restitution = 0.3
// Static rectangle
ground.physicsBody = SKPhysicsBody(rectangleOf: ground.size)
ground.physicsBody?.isDynamic = false
// Texture-based body for irregular shapes
player.physicsBody = SKPhysicsBody(texture: player.texture!, size: player.size)Use bit masks to control collisions and contact callbacks:
struct PhysicsCategory {
static let player: UInt32 = 0b0001
static let enemy: UInt32 = 0b0010
static let ground: UInt32 = 0b0100
}
player.physicsBody?.categoryBitMask = PhysicsCategory.player
player.physicsBody?.contactTestBitMask = PhysicsCategory.enemy
player.physicsBody?.collisionBitMask = PhysicsCategory.groundcategoryBitMask identifies the body. collisionBitMask controls physics
response (bouncing). contactTestBitMask triggers didBegin/didEnd.
Implement SKPhysicsContactDelegate and set physicsWorld.contactDelegate = self
in didMove(to:):
extension GameScene: SKPhysicsContactDelegate {
func didBegin(_ contact: SKPhysicsContact) {
let mask = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
if mask == PhysicsCategory.player | PhysicsCategory.enemy {
queuePlayerHit()
}
}
}Contact callbacks run during physics simulation. Make queuePlayerHit() set a
flag or append an event, then apply node/body/world mutations in update(_:).
player.physicsBody?.applyForce(CGVector(dx: 0, dy: 50)) // continuous
player.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 200)) // instant
player.physicsBody?.applyAngularImpulse(0.5) // spinUse .applyImpulse for jumps and projectile launches. Configure gravity with
physicsWorld.gravity = CGVector(dx: 0, dy: -9.8) and per-body with
affectedByGravity.
SKScene inherits from UIResponder. Override touchesBegan, touchesMoved,
touchesEnded on the scene. Use nodes(at:) to hit-test.
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
let location = touch.location(in: self)
let tappedNodes = nodes(at: location)
if tappedNodes.contains(where: { $0.name == "playButton" }) {
startGame()
}
}For node-level touch handling, subclass the node and set
isUserInteractionEnabled = true. That node then receives touches directly
instead of the scene.
SKCameraNode controls the visible portion of the scene. Add it as a child
and assign to scene.camera.
let cameraNode = SKCameraNode()
addChild(cameraNode)
camera = cameraNode
cameraNode.position = CGPoint(x: frame.midX, y: frame.midY)Update the camera position in didSimulatePhysics() or use constraints:
override func didSimulatePhysics() {
cameraNode.position = player.position
}
// Constrain camera to world bounds
let xRange = SKRange(lowerLimit: frame.midX, upperLimit: worldWidth - frame.midX)
let yRange = SKRange(lowerLimit: frame.midY, upperLimit: worldHeight - frame.midY)
cameraNode.constraints = [SKConstraint.positionX(xRange, y: yRange)]Scale the camera node inversely: setScale(0.5) zooms in 2x, setScale(2.0)
zooms out 2x. Nodes added as children of the camera stay fixed on screen
(HUD elements):
let scoreLabel = SKLabelNode(text: "Score: 0")
scoreLabel.position = CGPoint(x: 0, y: frame.height / 2 - 40)
scoreLabel.fontName = "AvenirNext-Bold"
scoreLabel.fontSize = 24
cameraNode.addChild(scoreLabel)SKEmitterNode generates particle effects. Design emitters in Xcode's
SpriteKit Particle File editor (.sks) or configure in code.
// Load from file
guard let emitter = SKEmitterNode(fileNamed: "Fire") else { return }
emitter.position = CGPoint(x: frame.midX, y: 100)
addChild(emitter)Set numParticlesToEmit for finite effects and remove after completion:
func spawnExplosion(at position: CGPoint) {
guard let explosion = SKEmitterNode(fileNamed: "Explosion") else { return }
explosion.position = position
explosion.numParticlesToEmit = 100
addChild(explosion)
let wait = SKAction.wait(forDuration: TimeInterval(explosion.particleLifetime))
explosion.run(SKAction.sequence([wait, .removeFromParent()]))
}Set targetNode to the scene so particles stay in world space when the
emitter moves: emitter.targetNode = self.
SpriteView embeds a SpriteKit scene in SwiftUI.
import SwiftUI
import SpriteKit
struct GameView: View {
@State private var scene: GameScene = {
let s = GameScene()
s.size = CGSize(width: 390, height: 844)
s.scaleMode = .resizeFill
return s
}()
var body: some View {
SpriteView(scene: scene)
.ignoresSafeArea()
}
}Pass options: [.allowsTransparency] for transparent backgrounds,
.shouldCullNonVisibleNodes for offscreen culling, or .ignoresSiblingOrder
for zPosition-based draw order. Use debugOptions: [.showsFPS, .showsNodeCount]
during development.
Pass data through a shared @Observable object. Store the scene in @State
to avoid re-creation on view re-renders:
@Observable final class GameState {
var score = 0
var isPaused = false
}
struct GameContainerView: View {
@State private var gameState = GameState()
@State private var scene = GameScene()
var body: some View {
SpriteView(scene: scene, isPaused: gameState.isPaused)
.onAppear { scene.gameState = gameState }
}
}.tessl-plugin
skills
accessorysetupkit
references
activitykit
adattributionkit
references
alarmkit
references
app-clips
app-intents
app-store-optimization
app-store-review
apple-on-device-ai
appmigrationkit
audioaccessorykit
references
authentication
references
avkit
background-processing
references
browserenginekit
callkit
references
carplay
cloudkit
contacts-framework
references
core-bluetooth
references
core-data
core-motion
references
core-nfc
references
coreml
references
cryptokit
cryptotokenkit
references
debugging-instruments
device-integrity
references
dockkit
energykit
references
eventkit
financekit
references
focus-engine
gamekit
healthkit
references
homekit
references
ios-accessibility
ios-app-workflow
references
ios-ettrace-performance
ios-localization
ios-memgraph-analysis
ios-networking
ios-simulator
references
metrickit
references
musickit
references
natural-language
references
paperkit
references
passkit
references
pdfkit
pencilkit
references
permissionkit
references
photokit
push-notifications
realitykit
references
relevancekit
references
scenekit
sensorkit
speech-recognition
references
spritekit
storekit
swift-api-design-guidelines
swift-architecture
references
swift-charts
swift-codable
references
swift-code-review
swift-concurrency
swift-formatstyle
references
swift-language
swift-security
references
swift-testing
swiftdata
swiftlint
swiftui-animation
swiftui-gestures
references
swiftui-layout-components
swiftui-liquid-glass
references
swiftui-patterns
swiftui-performance
swiftui-responsive-layout
swiftui-uikit-interop
swiftui-webkit
tabletopkit
tipkit
vision-framework
weatherkit
references