我一直被困在做Xcode中应该非常简单的事情上,我试图在场景中添加一个sprite,然后将它放在左下角:
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,不管方向如何。
如果这对答案有什么影响的话,我想把它固定在景观模式上?
我显然错过了一个非常基本的想法来设置现场,如果有人能提供任何线索,这将是非常感谢的。
谢谢。
发布于 2014-10-08 21:34:53
您必须编辑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章)
https://stackoverflow.com/questions/26265495
复制相似问题