[英]SKScene in UIViewController
I am making this app with multiple features, one of which is supposed to be a game. 我正在制作具有多种功能的应用程序,其中一项功能应该是游戏。 the normal collision game where you hit objects and score.
在普通的碰撞游戏中,您可以击中物体并得分。 but my app is a Single based application.
但我的应用程序是基于Single的应用程序。
when i create a new swift file, how can i add a SKScene to a UIViewController? 创建新的swift文件时,如何将SKScene添加到UIViewController?
any help will be appreciated. 任何帮助将不胜感激。
SKScene
needs to be added to an SKView
which is a subclass of UIView
. 需要将
SKScene
添加到作为UIView
的子类的SKView
中。 When you create the view controller, you can either set the view
property to be an SKView
or add an SKView
as a subview, then add your SKScene
to that SKView
via the presentScene:
method on SKView
. 当您创建视图控制器,你可以设置
view
属性是一个SKView
或添加SKView
作为一个子视图,那么你的加入SKScene
到SKView
通过presentScene:
上法SKView
。 Here's an example on how you could achieve that: 这是一个有关如何实现此目标的示例:
import SpriteKit
class SomeViewController: UIViewController {
func viewDidLoad() {
super.viewDidLoad()
let sceneView = SKView(frame: view.frame)
let scene = SKScene()
// Do any other scene setup here
view.addSubview(sceneView)
sceneView.presentScene(scene)
}
}
Sorry if there are small syntactical errors. 抱歉,如果语法上有小错误。 Didn't have a chance to test this and my memory of the SpriteKit API is hazy.
没有机会进行测试,我对SpriteKit API的记忆模糊。 Hope this helps!
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.