0

I am working in Swift and have created a basic game using SpriteKit in which squares move down the screen repeatedly and a sprite node "jumps" when tapped. Relatively simple. The game runs and looks as it should on every device, including the iPad air and iPad Retina, except for the iPad 2.

When I run the game on the iPad 2 simulator, the squares are way too big, have no space in between them, the node is way too big as well and only jumps maybe half a centimeter on the screen when tapped. The game is a mess.

Why is this occurring? Is there a way to specify in the code: if the device is an iPad 2, format and size everything in this manner? Or is there another way to fix this?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
blue
  • 7,175
  • 16
  • 81
  • 179

1 Answers1

0

The iPad 2 has the same resolution of the original iPad (1st Gen), so it has a resolution scale of 1.0. All you need to do is to check the iPad resolution and deppending on the results do what you need. Just add this extension and usage is pretty simple:

extension UIDevice{
    var iPad2: Bool {
        userInterfaceIdiom == .pad && UIScreen.main.scale == 1
    }
    var iPadRetina: Bool {
        userInterfaceIdiom == .pad && UIScreen.main.scale == 2
    }
}

usage:

if UIDevice.current.iPadRetina {
    // do whatever you need for the iPad with Retina Screens (2x)
}
if UIDevice.current.iPad2 {
    // do whatever you need for the iPad 2 without Retina (1x)
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571