Soo*_*lad 6 scene sprite-kit swift xcode6
我一直在坚持做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)
Run Code Online (Sandbox Code Playgroud)
这没有显示任何内容,因此我查看了场景维度是什么,self.frame.size.width和self.frame.size.height返回的宽度为1024,高度为768,无论方向如何.
如果这对答案有任何影响,我希望在横向模式下修复此问题吗?
我显然错过了一个非常基本的想法来设置场景,如果任何人可以放弃任何光线,将非常感激.
谢谢.
小智 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)
}
}
Run Code Online (Sandbox Code Playgroud)
您还应该设置场景大小
scene.size = skView.bounds.size
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
还有一个很好的教程,可以更好地解释这个:http: //www.raywenderlich.com/49721/how-to-create-a-breakout-game-using-spritekit (第1章或第2章)
| 归档时间: |
|
| 查看次数: |
8672 次 |
| 最近记录: |