Group Group Group Group Group Group Group Group Group

Game Size for devices that are not 16:9 ratio (iPhone X)


Is there a recommended way for us to fit the 2D Games onto the notched iOS devices? iPhoneX/R/S/SMax and iPhone 11/Pro/Max don’t really scale too well onto the game.

I’ve been able to deal with the problem by using the current used device’s aspect ratio to determine the playable rect like so:

	    let maxAspectRatio: CGFloat = CGFloat(Device.current.screenRatio.height / Device.current.screenRatio.width)
		let maxAspectRatioHeight = size.width / maxAspectRatio
		let playableMargin: CGFloat = (size.height - maxAspectRatioHeight) * 0.5

		playableRect = CGRect(x: 0, y: playableMargin, width: size.width, height: size.height - playableMargin * 2)

I got the Device code from here: DeviceKit

This works pretty well but it’s still not perfect, because any touches that are in the center and to the bottom of the screen will trigger the Home Indicator, so I ended up multiplying the margin by 0.6 and it became more easily playable.

I was just wondering what is the best way to go about this? I guess my method works but you still end up with empty spaces to the top and bottom of the game. Any comments or discussion would be greatly appreciated :grinning:


I found a few suggestions on stackoverflow:

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.