How do I get SpriteKit Playgrounds working in Xcode 8 beta?

2.5k views Asked by At

I want to be able to easily prototype my Sprite Kit code in Playgrounds. This works fine in Xcode 7

import UIKit
import SpriteKit
import XCPlayground


let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 480, height: 320))

let scene = SKScene(size: CGSize(width: 480, height: 320))
sceneView.showsFPS = true
sceneView.presentScene(scene)
XCPlaygroundPage.currentPage.liveView = sceneView

let square = SKSpriteNode(imageNamed: "square")
square.name = "shape"
square.position = CGPoint(x: scene.size.width * 0.25, y: scene.size.height * 0.5)

let circle = SKSpriteNode(imageNamed: "circle")
circle.name = "shape"
circle.position = CGPoint(x: scene.size.width * 0.50, y: scene.size.height * 0.5)

let triangle = SKSpriteNode(imageNamed: "triangle")
triangle.name = "shape"
triangle.position = CGPoint(x: scene.size.width * 0.75, y: scene.size.height * 0.5)

scene.addChild(square)
scene.addChild(circle)
scene.addChild(triangle)

In Xcode 7 I get a nice live view as such enter image description here

This just doesn't work in Swift 3 and Version 8.0 beta 3 (8S174q). What do I have to change?

1

There are 1 answers

6
mfessenden On BEST ANSWER

The XCPlayground module has been replaced by the PlaygroundSupport:

import PlaygroundSupport
import SpriteKit

let sceneView = SKView(frame: CGRect(x:0 , y:0, width: 480, height: 320))

let scene = SKScene(size: CGSize(width: 480, height: 320))
sceneView.showsFPS = true
sceneView.presentScene(scene)
PlaygroundSupport.PlaygroundPage.current.liveView = sceneView

let square = SKSpriteNode(imageNamed: "square")
square.name = "shape"
square.position = CGPoint(x: scene.size.width * 0.25, y: scene.size.height * 0.5)

let circle = SKSpriteNode(imageNamed: "circle")
circle.name = "shape"
circle.position = CGPoint(x: scene.size.width * 0.50, y: scene.size.height * 0.5)

let triangle = SKSpriteNode(imageNamed: "triangle")
triangle.name = "shape"
triangle.position = CGPoint(x: scene.size.width * 0.75, y: scene.size.height * 0.5)

scene.addChild(square)
scene.addChild(circle)
scene.addChild(triangle)