【发布时间】:2015-11-23 20:08:55
【问题描述】:
好的,下面是代码
class GameViewController: UIViewController, SceneTransitionDelegate,
GKGameCenterControllerDelegate, ADBannerViewDelegate {
var coolbool:Bool = false
...abunch of unimportant stuff functions and stuff
}
这就是我想要从我的 SKScene 中做的事情
func thing1()
{
let controller = GameViewController()
controller.coolbool = true
println(controller.coolbool) // Will say that it is true
sceneDelegate.transitionToScene(Menu.self) //Menu.self is the skscene that
we used to be in and will be in
}
func thing2()
{
println(controller.coolbool) // Will say that it is false
if (controller.coolbool == true)
{
//Put rainbows over every sprite and change generator settings
}
}
所以基本上发生的事情是“coolbool”被初始化为假。直到 thing1() 被调用导致变量“coolbool”改变。我在过渡之后立即确认其更改。但是在转换之后(到同一个场景(如果布尔为真,我试图让它看起来不同))如果你问值是什么,它说它是假的......即使我只是将它设置为真.
无论如何,我认为我做错了什么,他们是更好的方法吗???如果你想要它这里是转换函数
func transitionToScene(sceneClass:Scene.Type) {
playing = false
var sizeRect = UIScreen.mainScreen().applicationFrame
var width = sizeRect.size.width * UIScreen.mainScreen().scale
var height = sizeRect.size.height * UIScreen.mainScreen().scale
let skView = self.view as! SKView
let scene = sceneClass(size: skView.bounds.size)
scene.size = CGSizeMake(width, height)
rwidth = width
rheight = height
swidth = width
sheight = height
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
scene.sceneDelegate = self
skView.presentScene(scene)
}
【问题讨论】:
-
在你的方法 thing1() 之外声明 let controller = GameViewController()
-
@jtbandes 我真傻!这和coolbool是一回事,我重命名了它的所有实例,除了那个,我只是希望它易于人们阅读。
标签: swift sprite-kit skscene skview