本文介绍了如何让 xcode 在 GameScene.swift 而不是 GameScene.sks 中运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让 xcode 在 GameScene.swift 而不是 GameScene.sks 中运行代码?
How is it possible to get xcode to run the code inside of the GameScene.swift instead of GameScene.sks?
推荐答案
一切都在 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
}
它将运行GameScene.swift
中的代码,而不是GameScene.sks
中的代码.所以你可以通过代码创建节点.
it will run the code in GameScene.swift
instead of the code in GameScene.sks
. so you can create the nodes by code.
这篇关于如何让 xcode 在 GameScene.swift 而不是 GameScene.sks 中运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!