sprite-kit SKScene Subclassing SKScene to Implement Primary SpriteKit Functionality


SpriteKit functionality can be implemented in a subclass of SKScene. For example, a game may implement the main game functionality within an SKScene subclass called GameScene.

In Swift:

import SpriteKit

class GameScene: SKScene {

    override func didMoveToView(view: SKView) {
        /* Code here to setup the scene when it is first shown. E.g. add sprites. */

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for touch in touches {
            let location = touch.locationInNode(self)
            /* Code here to respond to a user touch in the scene at location */

    override func update(currentTime: CFTimeInterval) {
        /* Code here to perform operations before each frame is updated */

Secondary functionality could then be implemented in subclasses of the SKSpriteNodes that are used within the scene (see Subclassing SKSpriteNode).