3

I set my spriteKit game mode to be:

scene.scaleMode = .aspectFill

And I set my background image.

sky = SKSpriteNode(imageNamed: "Sky")
sky.position = CGPoint(x: 0, y: 0)
sky.size.width = self.size.width
sky.size.height = self.size.height
sky.anchorPoint = CGPoint(x: 0.5, y: 0.5)
sky.zPosition = 1
self.addChild(sky)

And the image size is 2732x2048. It looks terrible on 4.7 inch iPhone.
The whole thing is completed stretched.
Is there a way, to crop the image but not stretching it to fit it on iPhone (Same aspect radio for image).

I tried other scale modes, they don't work.
Can somebody tell me what's the right action to take now?

What if I provide iPhone artwork? How do I differentiate from code, like to specify which artwork iPhone should use, and which artwork iPad should use.

Tom Xue
  • 470
  • 1
  • 7
  • 18
  • if you are going to be using images that big, I would recommend changing your scene size to match it – Knight0fDragon Oct 14 '16 at 13:19
  • if you are providing iphone artwork, then you need to change your model, and not use scaleMode aspectFill, or do not make a universal app, and instead make an ipad app and an iphone app – Knight0fDragon Oct 14 '16 at 19:11

1 Answers1

4

Remove the lines where you set the size of the sky and you should accomplish the following tasks:

Don't set the size as the frame. Instead, set it to the size of the image, so it gets cropped rather than scaled:

sky.size = sky.texture.size

This code would be a replacement for the 2 lines you have that set its width and height.

This only works if your image size fits properly with its default size (size you made it in)

Alternatively, you could make your app universal like so. Take a look at this: iOS Universal Device App with SpriteKit, how to scale nodes for all views?. Then you simply make your background 1024x1024 (or any size big enough to fit all device sizes aspect ratio). This will crop part of it on devices that aren't the same size, but your aspect ratio won't change or scale for different devices.

Community
  • 1
  • 1
Nik
  • 1,664
  • 2
  • 14
  • 27