为什么它不能在快速2中显示任何东西?

我尝试在助理编辑器中使用spriteKit在操场上显示一些东西。 但是,没有显示。 下面是代码。 如果有任何人可以显示结果(一个蓝色的矩形),请通知我。 如果不是,请找出问题所在。

import UIKit import SpriteKit let view:SKView = SKView(frame: CGRectMake(0, 0, 1000, 800)) let scene:SKScene = SKScene(size: CGSizeMake(1000, 800)) scene.scaleMode = SKSceneScaleMode.AspectFit let blueBox: SKSpriteNode = SKSpriteNode(color: UIColor.blueColor(), size: CGSizeMake(300, 300)) blueBox.position = CGPointMake(512, 384) scene.addChild(blueBox) view.presentScene(scene) 

您可以通过单击边栏中的QuickLook(眼睛)或圆圈加button来查看当前的视图状态。 但是看到你的SpriteKit场景是animation的,你可能需要一个实时的视图。 为此,您需要XCPlayground框架。

 import XCPlayground XCPShowView("my SpriteKit view", view) 

有关详细信息,请阅读在Xcode帮助中浏览和评估游戏中的Swift代码或观看WWDC 2014会话408:Swift Playgrounds 。

由于在Xcode 7.1中不build议使用XCPShowView ,因此请改用PlaygroundPage中的PlaygroundSupport 。 以下是在Playground中使用SpriteKit的一个例子。

 import SpriteKit import PlaygroundSupport // Create the SpriteKit View let view = SKView(frame: CGRect(x: 0, y: 0, width: 500, height: 500)) // Create the scene and add it to the view let scene = SKScene(size: CGSize(width: 500, height: 500)) scene.scaleMode = SKSceneScaleMode.aspectFit scene.backgroundColor = .white view.presentScene(scene) // Add a red box to the scene let redBox = SKSpriteNode(color: SKColor.red, size: CGSize(width: 200, height: 200)) redBox.position = CGPoint(x: 250, y: 250) redBox.run(SKAction.repeatForever(SKAction.rotate(byAngle: -5, duration: 5))) scene.addChild(redBox) // Show in assistant editor PlaygroundPage.current.liveView = view PlaygroundPage.current.needsIndefiniteExecution = true