IOS: unable to get the correct screen size

I tried to display several SKNodes, and I used the width and height of the screen to set their positions, to make them compatible with different screen sizes.

SKNode* obstacle = [SKSpriteNode spriteNodeWithColor:[SKColor greenColor] size:obstacleSize];
obstacle.position = CGPointMake(80, self.size.height * 0.38);
obstacle.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:obstacle.frame.size];

But the positions of the nodes still change when I run the program with a different screen size (3.5 inches, but wrong in 4 inches). And I found that is self.size.heightnot the actual height of the screen.

Does anyone know how to solve this problem?

+4
source share
2 answers

[UIScreen mainScreen].bounds.sizereturns CGSize with the width and height of the screen. See Apple UIScreen Documentation .

+4

[UIScreen mainScreen].bounds.size CGSize . , , , .

0

Source: https://habr.com/ru/post/1524908/


All Articles