Liam Stockhomme
Liam Stockhomme

Reputation: 523

Does sprite-kit make images larger?

I'm working on a sprite kit game and I can't figure out why it won't scale my image the way I want it to. The game is in the landscape orientation. This is the code I'm having a problem with:

SKSpriteNode *Pathway = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:@"path.png"] size:CGSizeMake(568, 220)];
Pathway.zPosition = -1.0;
Pathway.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
Pathway.name = @"Pathway";

[self addChild:Pathway];

Basically I want the texture to be like this on the screen: enter image description here

But for some reason, even when I change the size of the texture (568, 220), it scales the image and doesn't fit on the screen.

I tried using [Pathway setScale:0.7]; which was close to the size I was looking for, but I need to to be exactly 568 x 220. How come it keeps distorting my image even when I'm setting its size of 568 x 220?

If more info is needed please let me know, I think this should suffice.

Upvotes: 1

Views: 251

Answers (2)

Andrey Gordeev
Andrey Gordeev

Reputation: 32459

I'm pretty sure you are testing this on device with Retina display.

Rename path.png to [email protected] and use [SKTexture textureWithImageNamed:@"path"] instead of [SKTexture textureWithImageNamed:@"path.png"]. This should solve you problem.

Read Apple's tutorial Supporting High-Resolution Screens In Views for more info.

Upvotes: 7

RamaKrishna Chunduri
RamaKrishna Chunduri

Reputation: 1130

Using setScale directly scales content proportional and thus resulting in the sprite that follows same aspect ratio as it is before scaling.

Try setting xScale and yScale properties to scale irrespective of aspect ratio

Upvotes: 0

Related Questions