I have a problem with positioning a sprite to correct point in a game scene. As far as I read position and anchorpoint and spritekit programming guide it should be clear that 0,0 is at the bottom left corner. I use landscape mode only.
But when I use my code:
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
var ground = createGround()
self.addChild(ground)
}
func createGround()->SKSpriteNode {
var ground = SKSpriteNode(imageNamed: "ground.png")
ground.name = "ground"
ground.anchorPoint = CGPointMake(0, 0)
ground.position = CGPointMake(0, 0)
return ground
}
}
And I implement scene pretty standard untouched:
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let 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.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
This is the result:
My "ground.png" has a size of 120x120. I double-checked scenes anchor, it's at (0,0) and even when I set it in didMoveToView to (0,0), I've still same problem.
Somehow the Y factor is messed up. When I set ground position to (0,156) it's directly in the botton left corner. So it looks like game scenes y-anchor-point is -36 and anchor-point of ground is at top left instead of bottom left. Any clues why?
I found almost same problem but frame looks good with (0.0, 0.0, 1024.0, 768.0).
override func viewWillLayoutSubviews()
doesn't work ... sorry, I'm REALLY new to this stuff. – Jurik