我一直在做Xcode中应该是非常简单的事情,我试图在场景中添加一个精灵并让它坐在左下角:
var groundTexture : SKTexture = SKTexture(imageNamed: "dirt-block")
var ground : SKSpriteNode = SKSpriteNode(texture: groundTexture)
ground.position = CGPointMake(ground.size.width/2, ground.size.height/2)
self.addChild(ground)
这没有显示任何内容,所以我看了一下场景尺寸是什么,self.frame.size.width和self.frame.size.height返回的宽度为1024,高度为768,无论如何方向。
如果对答案有任何不同,我希望在横向模式下修复此问题吗?
我显然错过了一个非常基本的想法来设置场景,如果任何人都可以放下任何光线,那将非常感激。
感谢。
答案 0 :(得分:17)
你必须编辑GameViewController:
从viewDidLoad()
除super.viewDidLoad()
覆盖viewWillLayoutSubviews
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
var skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.size = skView.bounds.size
scene.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
此外,您应该设置场景大小,如您所见
scene.size = skView.bounds.size
希望这有帮助
还有一个很棒的教程可以更好地解释这个问题: http://www.raywenderlich.com/49721/how-to-create-a-breakout-game-using-spritekit (第1章或第2章)