I was creating a Swift Playground using SpriteKit but was having multiple issues. Below is my code:
// 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
}
Keep in mind that I have omitted a lot of other code that sets up the individual SKSpriteNodes
. The errors that I am getting are as follows:
Expected Declaration on both the currentScene.addChild(node1) and on the view.presentScene(scene)
Use of unresolved identifier screenFrame
on the fourth to last line.
I would appreciate it if you guys could help me solve this as I need to get this project done soon.