Liam Stockhomme
Liam Stockhomme

Reputation: 523

Why won't this image fit to the screen size?

I posted a question yesterday trying to figure out why the sprite kit was distorting my image. I was given a great answer, however it was only semi-helpful for my problem.

I was told to name the image name@2x.png then to only call name in the code and that it would solve the problem. Unfortunately this didn't work.

This is what I was getting before trying that:

enter image description here

Code:

SKSpriteNode *background = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:@"bgs.png"] size:CGSizeMake(568,320)];
background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));

[self addChild:background];

But after changing the images name to bgs@2x.png, and only writing bgs in the code, this is what I got:

enter image description here

Code:

    SKSpriteNode *background = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:@"bgs"]];
    background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));

    [self addChild:background];

Which is closer to what I want but obviously still not right.

Why won't it just fit to screen? What is going on that it either stretches the image too much or compresses the image too little?

IMAGE DIMENSIONS: 568 x 320 GAME ORIENTATION: Landscape

Upvotes: 1

Views: 541

Answers (1)

Andrey Gordeev
Andrey Gordeev

Reputation: 32549

Your @2x image size must be 1136x640 to fill the whole screen. Just renaming it won't do the trick.

Upvotes: 2

Related Questions