I am exploring SpriteKit game development for fun, and I came across a seemingly simple problem that puzzled me.
Basically, after scaling the textured SKSpriteNode, the frame is NOT what I expect. I figured out a few hacks to get it to what I want, but I'm trying to figure out what is going on. Any ideas appreciated!
Here is my code WITHOUT ANYTHING:
func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" // spaceship.setScale(0.50) let debugFrame = SKShapeNode.init(rect: spaceship.frame) debugFrame.strokeColor = SKColor.greenColor() spaceship.addChild(debugFrame) spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - 150) self.addChild(spaceship) }
And my application looks like this: 
Now, if I comment in a line of code that scales it (spaceship.setScale (0.50)), I get the following:

Note that the spaceship is reduced in the second image, but the frame is even smaller. Why?
If I move the zoom line after adding the spacecraft to the scene, it does what I expect, but it seems wrong:
Here the code with setScale is called after adding the spacecraft to the scene:
func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" let debugFrame = SKShapeNode.init(rect: spaceship.frame) debugFrame.strokeColor = SKColor.greenColor() spaceship.addChild(debugFrame) spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - 150) self.addChild(spaceship) spaceship.setScale(0.50) }
And here is how my application works:

So what works, but why is it needed?
It was suggested below that this is a bug with SKShapeNode. But replacing SKShapeNode with SKLabelNode has the same problem:
func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" spaceship.setScale(0.50) let scoreNode = SKLabelNode(text: "100") scoreNode.position = CGPointMake(CGRectGetMidX(spaceship.frame), CGRectGetMaxY(spaceship.frame)) scoreNode.fontColor = SKColor.redColor() scoreNode.fontSize = 15.0 scoreNode.fontName = "Monaco" scoreNode.zPosition = 10.0 spaceship.addChild(scoreNode) spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - 150) self.addChild(spaceship) }
which gives us:

The goal is for the score label (scoreNode) to be centered over the rocket, but as you can see, it is on top of the top porthole. There is something wrong with the spacecraft frame after I call spacehip.setScale.
I made one additional discovery: the setScale call should not be after adding a spaceship to the scene. It just has to be after I add debugFrame / scoreNode to the spaceship. If I set DOWNLOAD AFTER this point, everything will be fine:
func addSpaceship() { let spaceship = SKSpriteNode.init(imageNamed: "rocketship.png") spaceship.name = "spaceship" let scoreNode = SKLabelNode(text: "100") scoreNode.position = CGPointMake(CGRectGetMidX(spaceship.frame), CGRectGetMaxY(spaceship.frame)) scoreNode.fontColor = SKColor.redColor() scoreNode.fontSize = 15.0 scoreNode.fontName = "Monaco" scoreNode.zPosition = 10.0 spaceship.addChild(scoreNode) spaceship.setScale(0.50) spaceship.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame) - 150) self.addChild(spaceship) }
that leads to:
