I have this code to put a score label for my game in the top left corner of the screen.
scoreLabel = SKLabelNode(text:"bats avoided: \(score)")
scoreLabel.fontSize = 50
scoreLabel.horizontalAlignmentMode = .left
scoreLabel.position = CGPoint (x:10 - (frame.size.width/2), y: (frame.size.height/2) - 50)
but the label appears on iPhone simulator only, not iPad.
If I print the portion of the label at runtime, it shows that the position is x: -365 y:617 with a screen width/2 of 375 and screen height/2 of 667, so it should definitely be there.
what gives?
The coordinate system in iOS represents 'top left' as 0,0. That is to say that as you increase x, you move to the right and as you increase y, you move down.
You are setting a value of
10 - (frame.size.width/2)for x. Suppose yourframe.size.widthis 300, for example, this would be equal to-140. Remember how I said 'top left' is represented as 0,0? Well, if you have an x coordinate of-140, the element will be further left than 0,0, and subsequently offscreen.To place something in the top left, inset by 10 points. You would simply set it's position to be
CGPoint(x: 10, y: 10).It is worth noting that when working with sprites, as in your case, that Y0 is actually the bottom, rather than the top of the screen. This a somewhat annoying discrepancy but one to keep in mind.