Chris Jones
Chris Jones

Reputation: 857

Spritenodes appear stretched

I'm trying to set the custom size of a spritenode. Here is my code:

    var twitterIcon = SKSpriteNode(imageNamed: "Twitter")
    twitterIcon.size = CGSizeMake(80, 80)
    twitterIcon.position = CGPointMake(70, self.frame.size.height - 70)
    twitterIcon.zPosition = 3
    twitterIcon.name = twitterCategoryName

The problem is that it appears as an oval

spritenode

I figure it might be a problem with the way the GameScene is set up - but I'm not sure

sks

Side note - this happens only on iPhones. When testing on the iPad it works fine.

Upvotes: 0

Views: 82

Answers (1)

Skyler Lauren
Skyler Lauren

Reputation: 3812

It sounds like the issue is you have your aspect set to Fill. This does not maintain your ratio and will cause skewing.

What you would really want is AspectFit or AspectFill. Those will resize the scene without changing your scenes aspect ratio. The issue is because your scene is 4:3 it will crop or add black bars depending on your choice (most go with cropping but special considerations have to be made for placement of items)

typedef NS_ENUM(NSInteger, SKSceneScaleMode) {
    SKSceneScaleModeFill,           /* Scale the SKScene to fill the entire SKView. */
    SKSceneScaleModeAspectFill,     /* Scale the SKScene to fill the SKView while preserving the scene's aspect ratio. Some cropping may occur if the view has a different aspect ratio. */
    SKSceneScaleModeAspectFit,      /* Scale the SKScene to fit within the SKView while preserving the scene's aspect ratio. Some letterboxing may occur if the view has a different aspect ratio. */
    SKSceneScaleModeResizeFill      /* Modify the SKScene's actual size to exactly match the SKView. */ 
} NS_ENUM_AVAILABLE(10_9, 7_0);

It makes sense because iPad is 1024 x 768 (same as your sks scene) which is 4:3 aspect ratio where your iPhone will be 16:9 (if an iPhone 5 or higher). You can't fit that in the screen without cropping, black bars, or skewing.

Hopefully that makes sense and is helpful.

Upvotes: 1

Related Questions