问题
How is it possible to get xcode to run the code inside of the GameScene.swift instead of GameScene.sks?
回答1:
Everything is in GameViewController
if let view = self.view as! SKView? {
// Load the SKScene from 'GameScene.sks'
if let scene = SKScene(fileNamed: "GameScene") {
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
}
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
you can change it by replacing with this code
if let view = self.view as! SKView? {
let scene = GameScene(size: view.bounds.size)
// Set the scale mode to scale to fit the window
scene.scaleMode = .aspectFill
// Present the scene
view.presentScene(scene)
view.ignoresSiblingOrder = true
view.showsFPS = true
view.showsNodeCount = true
}
it will run the code in GameScene.swift
instead of the code in GameScene.sks
. so you can create the nodes by code.
来源:https://stackoverflow.com/questions/41206712/how-do-i-get-xcode-to-run-the-code-in-gamescene-swift-instead-of-gamescene-sks