Christopher Hannah
Christopher Hannah

Reputation: 1748

Get proper position/resolution for SpriteKit game

I've got a very tedious issue. I'm playing around with Swift and trying to make a basic game, except i want to position sprites randomly across the width of the screen. Also, I want to position some labels such as the running score in the top left/right part of the screen.

The trouble is when I get the values of the scenes frame I get 1024, 768 on an iPhone 5 Simulator, and I can't seem to find a way to get the real height/width of the screen so I can properly position everything.

Hopefully it's something simple I just haven't worked out.

Thanks in advance!

Upvotes: 1

Views: 224

Answers (1)

l.vasilev
l.vasilev

Reputation: 930

Check this method for getting center and adjust them yourLabel.position = CGPointMake(CGRectGetMidX(self.frame) CGRectGetMidY(self.frame)); OR Try For a label in the top left corner:

label.horizontalAlignmentMode = .Left
label.position = CGPoint(x:0.0, y:self.size.height)

Or for the top right:

label.horizontalAlignmentMode = .Right
label.position = CGPoint(x:self.size.width, y:self.size.height)

I Hope that helps.:)

Upvotes: 2

Related Questions