Skip to content

Instantly share code, notes, and snippets.

@mminer
Last active September 29, 2016 04:27
Show Gist options
  • Save mminer/b17855651b5d010850b4d39b78a76af5 to your computer and use it in GitHub Desktop.
Save mminer/b17855651b5d010850b4d39b78a76af5 to your computer and use it in GitHub Desktop.
Xcode playground starter code to experiment with SpriteKit.
import PlaygroundSupport
import SpriteKit
// Set up scene:
let size = CGSize(width: 480, height: 320)
let scene = SKScene(size: size)
scene.physicsBody = SKPhysicsBody(edgeLoopFrom: scene.frame)
scene.physicsWorld.gravity = CGVector.zero // Enabled later
let sceneView = SKView(frame: CGRect(origin: CGPoint.zero, size: size))
sceneView.showsFPS = true
sceneView.showsNodeCount = true
sceneView.showsPhysics = true
sceneView.presentScene(scene)
PlaygroundPage.current.liveView = sceneView
// Code here...
// Briefly pause before enabling gravity so that we don't miss some action while the playground starts execution.
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
scene.physicsWorld.gravity = CGVector(dx: 0, dy: -9.8)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment