0

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.

sangony
  • 11,636
  • 4
  • 39
  • 55
Chris Jones
  • 856
  • 1
  • 11
  • 24

1 Answers1

1

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.

Skyler Lauren
  • 3,792
  • 3
  • 18
  • 30
  • 1
    Setting the `scaleMode` to `resizeFill` resizes the scene to the size of the view. It does not resize the contents of the scene; therefore, it doesn't cause skewing. – 0x141E Jul 09 '15 at 17:03
  • @0x141E You are correct and I edited my answer thank you =) – Skyler Lauren Jul 12 '15 at 11:16