如何让 SpriteKit Playgrounds 在 Xcode 8 beta 中工作?
How do I get SpriteKit Playgrounds working in Xcode 8 beta?
我希望能够在 Playgrounds 中轻松制作我的 Sprite Kit 代码原型。
这在 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)
在 Xcode 7 中,我得到了一个不错的实时视图
这在 Swift 3 和版本 8.0 beta 3 (8S174q) 中不起作用。
我必须改变什么?
XCPlayground
模块已替换为 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)
我希望能够在 Playgrounds 中轻松制作我的 Sprite Kit 代码原型。 这在 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)
在 Xcode 7 中,我得到了一个不错的实时视图
这在 Swift 3 和版本 8.0 beta 3 (8S174q) 中不起作用。 我必须改变什么?
XCPlayground
模块已替换为 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)