i just started a new Sprite Kit project to learn how to use it. I watched and read a lot of tutorials but no tutorial has a answer for my question/problem.
I want to
Solution:
Put this code into your viewWillLayoutSubviews instead into the viewDidLoad of the UIViewController which loads the sprite.
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
if (!skView.scene) {
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
Explanation : This creates the scene with a size as the bounds of the view. However, when viewDidLoad is called, this is before the view has been added to the view hierarchy and hence it hasn’t responded to layout changes yet. So the view bounds might not be correct yet, and this probably isn’t the best time to start up the scene.
This answer is copied from : http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners The credit goes to Ray :).
I have used the same code in my SKScene like you, but without this solution Ray offered in the UIViewController which presents the scene it would not work.