我正在使用SpriteKit创建一个Swift Playground但是有多个问题。以下是我的代码:
// Setup
import SpriteKit
import Foundation
import UIKit
import PlaygroundSupport
public class GameScene: SKScene, SKPhysicsContactDelegate {
var currentScene: SKScene? = nil
var sceneFrame: CGRect? = nil
override public func didMove(to view: SKView) {
physicsWorld.contactDelegate = self
//Setup Variables Here
}
override init() {
sceneFrame = CGRect(x: 0, y: 0, width: 640, height: 320)
currentScene = SKScene(size: sceneFrame!.size)
scene?.backgroundColor =
UIColor(red:0.60, green:0.88, blue:1.00, alpha:1.0)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
var timer: Timer?
trashCreator = Timer.scheduledTimer(withTimeInterval: 4, repeats: true) { (timer) in
createNode()
}
func createNode() {
let node = SKSpriteNode(imageNamed: "node")
scene!.addChild(trash)
}
//Add Everything to the View
currentScene.addChild(node1)
currentScene.addChild(node2)
//scene.addChild(floor)
let view = SKView(frame: screenFrame)
view.presentScene(scene)
PlaygroundPage.current.liveView = view
}
请注意,我已经省略了许多设置个人SKSpriteNodes
的其他代码。我得到的错误如下:
currentScene.addChild(node1)和view.presentScene(场景)上的预期声明
在倒数第四行使用未解析的标识符screenFrame
。
如果你们能帮助我解决这个问题,我将不胜感激,因为我需要很快完成这个项目。