iOS SpriteKit node position

855 views Asked by At

I an new at Sprite kit and I want to add some node to scene. My problem is positions :

If I put :

SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Poligon"];
sprite.xScale = 0.5;
sprite.yScale = 0.5;
sprite.position = CGPointMake(40, 400);

it looks right when iPhone is in landscape mode, but when it is in portrait it disappear from the screen.

My guess is that it take coordinate from landscape and put it at right side of the screen. This would explain why node is not visible in portrait mode.

My question is how to set that iPhone would take portrait mode by default?

1

There are 1 answers

0
Marko Zadravec On

Apparently sprite kid start in landscape mode and take start viewDidLoad before it take rotation in account. Because of this the coordinate system in portrait mode is shifted, even if you set orientation to portrait.

enter image description here

The solution according to :

http://www.ymc.ch/en/ios-7-sprite-kit-setting-up-correct-scene-dimensions

is to set your scene not on viewDidLoad but on

- (void)viewWillLayoutSubviews

This is run after orientation is set and it works.