我正在使用样板代码(新游戏iOS项目)的标准全屏SpriteKit视图,当我使用时
scene.scaleMode = .AspectFit
为了确保场景适合,剩余(letterBoxed)区域用黑色着色.
我尝试过这些选项来改变颜色:
let skView = self.view as SKView // was hoping this one would work skView.backgroundColor = UIColor.redColor() // didn't expect this would work,since scene is scaled anyways scene.backgroundColor = SKColor.redColor()
还尝试将故事板编辑器中的SKView背景颜色更改为另一种颜色,但没有运气.
关于在哪里寻找改变信箱区域颜色的任何提示?
解决方法
我认为应该是一种设置颜色或将精灵放在信头的耳朵中的方法……但似乎没有.另外,我不同意LearnCocos2D. AspectFit没有任何问题.它有它的用途.
我所做的是使用AspectFit,但也根据屏幕大小计算场景的大小.这对OSX游戏没什么帮助,但对iOS来说它可以正常工作.
func createScene() -> GameScene { let screenSize = UIScreen.mainScreen().bounds.size var size:CGSize = CGSizeZero size.height = Constants.sceneHeight size.width = screenSize.width * (size.height / screenSize.height); return GameScene(size: size) } override func viewDidLoad() { super.viewDidLoad() let scene = self.createScene() // Configure the view. let skView = self.view as SKView skView.showsFPS = false skView.showsNodeCount = false /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ scene.scaleMode = .AspectFit skView.presentScene(scene) }