Thursday, May 4, 2017

Swift SKSpiteNode position iPhone V iPad

Leave a Comment

I have positioned a node at the top left of the view in my app using the following code:

health = SKSpriteNode(color: .green, size: CGSize(width: progressValue, height: 50)) health.position = CGPoint(x: -self.frame.width / 2, y: self.frame.height / 2) 

This positions correctly in all iPhone simulators, ranging from 5 to 7 Plus.

However, it doesn't appear in any iPad simulator. I've set the position to midX and midY and it appeared fine just not with the code shown above which works perfectly for all iPhones.

What am I missing?

Is there a different way to position nodes on the view for an iPhone v iPad instead of using multiples of the view?

1 Answers

Answers 1

SOLVED:

The problem was that the scene scaleMode was set to .aspectFill which worked great for the iPhones just not for the iPads.

However .resizeFill worked perfectly so this is what I did.

if UIDevice.current.userInterfaceIdiom == .pad {                  scene.scaleMode = .resizeFill              }else{                  scene.scaleMode = .aspectFill               } 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment