아이폰 X 화면을 지원하는 SpriteKit 게임 청소기 방법이있을 수 있습니다,하지만 난 GameViewController에 대한 다음과 같은 확장자로 나온 :
import SpriteKit
class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let view = self.view as? SKView {
if let scene = SKScene(fileNamed: "yourscenefilename") {
// Set the scale mode according to the device
if isIphoneX {
scene.scaleMode = .resizeFill
} else {
scene.scaleMode = .aspectFill
}
// Any additional setup...
...
// Present the scene
view.presentScene(scene)
}
}
}
}
extension GameViewController {
var isIphoneX: Bool {
let aspectRatio = Double(view.frame.width/view.frame.height)
let iphoneXAspectRatio = 2436.0/1125.0
return (aspectRatio == iphoneXAspectRatio) ? true : false
}
}
은 기본적으로는 설정 화면의 가로 세로 비율에 따라 가로 세로 비율을 조정할 수 있습니다. iPhone X 가로 세로 비율 인 경우 크기 조절 모드를 "resizeFill" 그렇지 않으면 클래식 사각형 iPhone 및 iPad 화면에서 "aspectFill"모드를 사용하십시오.
resizeFill 모드는 장면의 내용을 왜곡하거나 잘라 내지 않고 전체 iPhone X 화면을 채울 수있는 유일한 방법입니다. 게임에 HUD 노드가 있다면 (스코어, 카운터, 버튼 등), 변경해야합니다!
override func didMove(to view: SKView) {
// Any additional setup...
...
if isIPhoneX {
hud = SKReferenceNode(fileNamed: "yourIPhoneXHUDScene")
} else {
hud = SKReferenceNode(fileNamed: "yourStandardHUDScene")
}
cam.addChild(hud)
}
시뮬레이터의 모든 아이폰의 화면 크기 (3.5 ", 4", 4.7 ", 5.5", 5.8 ")와 테스트. 내가 망막 아이 패드 크기 gamescenes (처리하는 방법을 잘 모르겠어요하지만 2048 x 1536의)은 엑스 코드에서 설정합니다.