Spritekit scale full game to iPad

后端 未结 2 999
醉梦人生
醉梦人生 2020-12-19 15:54

So I\'m developing a game on Xcode using Spritekit, for the iPhone. And it looks all the same and great on all iPhone devices, by using the node.setScale() method. Now I wan

2条回答
  •  青春惊慌失措
    2020-12-19 16:48

    If you are using SKCameraNode then you can scale the entire scene by scaling the camera.

    // SKCameraNode+Extensions.swift
    extension SKCameraNode {
        func updateScaleFor(userInterfaceIdiom: UIUserInterfaceIdiom) {
            switch userInterfaceIdiom {
                case .phone:
                    self.setScale(0.75)
                case .pad:
                    self.setScale(1.0)
                default:
                    break
            }
        }
    }
    

    Then call it when your scene initializes.

    guard let camera = self.childNode(withName: "gameCamera") as? SKCameraNode else {
        fatalError("Camera node not loaded")
    }
    
    // Update camera scale for device / orientation
    let userInterfaceIdiom = UIDevice.current.userInterfaceIdiom 
    camera.updateScaleFor(userInterfaceIdiom: userInterfaceIdiom)
    

提交回复
热议问题