Skip to content
Mobile
Skill

/spritekit

Build 2D games and animations using SpriteKit. Use when creating game scenes with SKScene and SKView, adding sprites with SKSpriteNode, animating with SKAction sequences, simulating physics with SKPhysicsBody and contact detection, creating particle effects with SKEmitterNode,

From plugin
swift-ios-skills
1.3k86 skills1 MCP

Claude Code

$ npx -y skills add dpearson2699/swift-ios-skills --skill spritekit --agent claude-code

SKILL.md

spritekit.SKILL.md
name: spritekit
description: "Build 2D games and animations using SpriteKit. Use when creating game scenes with SKScene and SKView, adding sprites with SKSpriteNode, animating with SKAction sequences, simulating physics with SKPhysicsBody and contact detection, creating particle effects with SKEmitterNode, building tile maps, using SKCameraNode, or integrating SpriteKit scenes in SwiftUI with SpriteView."

SpriteKit

Build 2D games and interactive animations for iOS 26+ using SpriteKit and Swift 6.3. Covers scene lifecycle, node hierarchy, actions, physics, particles, camera, touch handling, and SwiftUI integration.

Contents

  • [Scene Setup](#scene-setup)
  • [Nodes and Sprites](#nodes-and-sprites)
  • [Actions and Animation](#actions-and-animation)
  • [Physics](#physics)
  • [Touch Handling](#touch-handling)
  • [Camera](#camera)
  • [Particle Effects](#particle-effects)
  • [SwiftUI Integration](#swiftui-integration)
  • [Common Mistakes](#common-mistakes)
  • [Review Checklist](#review-checklist)
  • [References](#references)

Scene Setup

SpriteKit renders content through `SKView`, which presents an `SKScene` -- the root node of a tree that the framework animates and renders each frame.

Creating a Scene

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.
    }
}

Presenting a Scene (UIKit)

guard let skView = view as? SKView else { return }
skView.ignoresSiblingOrder = true

let scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .resizeFill
skView.presentScene(scene)

Scale Modes

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.

Frame Cycle

Each frame follows this order:

1. `update(_:)` -- game logic 2. Evaluate actions 3. `didEvaluateActions()` -- post-action logic 4. Simulate physics 5. `didSimulatePhysics()` -- post-physics adjustments 6. Apply constraints 7. `didApplyConstraints()` 8. `didFinishUpdate()` -- final adjustments before rendering

Override only the callbacks where work is needed.

Nodes and Sprites

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.

Common Node Types

| 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 |

Creating Sprites

let player = SKSpriteNode(imageNamed: "hero")
player.position = CGPoint(x: frame.midX, y: frame.midY)
player.name = "player"
addChild(player)

Drawing Order

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 = 10

Naming and Searching

Assign `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 { /* ... */ }

Actions and Animation

`SKAction` objects define changes applied to nodes over time. Actions are immutable and reusable. Run with `node.run(_:)`.

Basic Actions

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()

Combining Actions

// 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)
    ])
)

Texture Animation

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 later

Physics

SpriteKit provides a built-in 2D physics engine. The scene's `physicsWorld` manages gravity and collision detection.

Adding Physics Bodies

// 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?.
Read more
@dpearson2699
Ships withswift-ios-skills

86 agent skills optimized for iOS 26+ development with Swift 6.3 and modern Apple frameworks.

1.3k86 skills1 MCP
Get the whole plugin

Stars on GitHub

Momentum

stars in total
1.3k
Star history of dpearson2699/swift-ios-skills on GitHub, a chart by star-history.com

Other skills on swift-ios-skills.

alarmkit

alarmkit

Implement AlarmKit alarms and countdown timers for iOS and iPadOS with Lock Screen, Dynamic Island, StandBy, and paired Apple…

app-clips

app-clips

Build iOS App Clips with invocation URLs, App Clip Codes, NFC, QR codes, Safari banners, Maps, Messages, target setup, App Store…

More skills from other plugins.

deep-code-review

deep-code-review

In-depth design-focused code review - understands codebase context before evaluating PR changes, posts structured feedback to…

expo1d53k
@expo@expoInstall Skill
modlens

modlens

Plug-in vision for text-only models. Hard rule: when a file path or URL with an image extension (.png, .jpg, .jpeg, .webp, .gif,…

modlens2w4.6k
@liustack@liustackInstall Skill
appllama-app-design-skill

appllama-app-design-sk…

Build native-feeling, benchmark-quality mobile app screens (Expo / React Native). Use when designing or implementing any mobile…

appllama2mo3.9k
@appllama@appllamaInstall Skill

Questions about spritekit.

Which coding agents can use spritekit?
spritekit installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.