2017-02-18 77 views
0

我已经设置了场景并且一切正常。它看起来像这样:enter image description hereSKNodes不在场景中显示

但控制器是在Main.storyboard中设置的,我想摆脱它。所以我做了这样的事情:

window = UIWindow(frame: UIScreen.main.bounds) 
    window?.makeKeyAndVisible() 
    window?.rootViewController = GameViewController() 

中的appDelegate这:

override func loadView() { 
    super.loadView() 
    self.view = SKView() 
} 

在GameViewController加载它。第一次,现场加载,但只有绿色背景,没有其他节点。 (节点计数器显示正确的节点数。)

所以我试着设置ignoresSiblingOrder都是true和false,scene.scaleMode的所有选项和我实现的最好结果是scene.scaleMode = .resizeFill。是这样的: enter image description here

编辑: 位置为界:

greenOne.position = CGPoint(x: greenOne.radius + sticksOffset, y: greenOne.radius + sticksOffset) 
redOne.position = CGPoint(x: self.frame.maxX - redOne.radius - sticksOffset/2, y: view.bounds.size.height/2) 

尝试这样做,重做出现旁边的绿色

redOne.position = CGPoint(x: redOne.radius + 100, y: 200) 

看来这个观点并不符合屏幕太大。

+0

那么只有绿色的圆圈和背景显示? – sicvayne

+0

是的,只有绿色的一个,虽然所有的圆都有相同的设置.. –

+0

我看到了,你能提供更多的代码吗?也许显示这些圈子是如何设置的。 – sicvayne

回答

0

通过改变视图的init在GameViewController解决:

override func loadView() { 
    super.loadView() 

    self.view = SKView(frame: UIScreen.main.applicationFrame) 
} 

旧版本的看法有零的宽度和高度,所以GameScene没有得到任何尺寸。

+0

自iOS 9.0以来,'applicationFrame属性已被弃用。你可能想要使用'UIScreen.bounds',或者只使用'self.view = SKView(frame:self.view.frame)' – Whirlwind

相关问题