SKScene bounds and positioning

286 views Asked by At

I'm trying my best to use my "responsive" / "adaptive" knowledge to apply it to positioning in my SKScene.

However, it would appear there's a problem. As the width / height of the scene aren't accurate.

In this example, the view's anchor point is centerpoint i.e 0.5, 0.5.

    SKLabelNode *label = [SKLabelNode labelNodeWithText:@"Welcome to the table..."];
    label.position = CGPointMake(0,0);
    label.alpha = 0;
    [self addChild:label];

now let's say, I want to move that to the bottom of the screen. I use the screen sizing logic so I can apply it for every device.

label.position = CGPointMake(0, self.view.frame.height/2 + label.frame.height);

From what I can see, it should align the X to the anchor point, then deduct y from the anchor point. So CenterPoint - half screen height + label height.. However, this isn't the case. It's offscreen somewhere not working accurately.

I've also tried this with self.frame.size.height & self.view.bounds.size.height

1

There are 1 answers

0
ABakerSmith On BEST ANSWER

It sounds like the size of your SKScene doesn't match the size of its SKView. Try setting the scaleMode of your scene to ResizeFill. From the SKScene documentation on ResizeFill:

The scene is not scaled to match the view. Instead, the scene is automatically resized so that its dimensions always match those of the view.