如何缩放半径以适应所有设备?

How to scale a radius to fit in all devices?

我正在制作一个球沿着路径运动的游戏,实际上只是一种幻觉,因为场景是旋转的。问题在于,在某些设备中,球会离开屏幕,而在其他设备中,半径看起来很小。我试图使半径相等 (orbita.size.width / 2) 但它不起作用。 (orbita 是球所遵循的轨道)

  class GameScene: SKScene {

   let sprite = SKSpriteNode(imageNamed: "circulo")
var rotation:CGFloat = CGFloat(M_PI)
let radius:CGFloat = 168


override func didMoveToView(view: SKView) {
    /* Setup your scene here */

    scaleMode = .ResizeFill
    node.position = view.center
    // 3) Add the container to the scene
    addChild(node)
    // 4) Set the sprite's x position
    sprite.position = CGPointMake(radius, 0)
    // 5) Add the sprite to the container
    node.addChild(sprite)
    // 6) Rotate the container
   rotate()
    sprite.color = UIColor.whiteColor()
    sprite.colorBlendFactor = 1.0
    sprite.zPosition = 4.0



    orbita = SKSpriteNode(imageNamed: "orbita")
    let padding2:CGFloat =  32.0
    orbita.size = CGSize(width:view.frame.size.width - padding2 , height: view.frame.size.width - padding2)
    orbita.color = UIColor.whiteColor()
    orbita.colorBlendFactor = 1
     orbita.alpha = 1
   orbita.position = view.center
    self.addChild(orbita)
    orbita.zPosition = 3
}

如果你的 orbita.size 是("circulo" 名称似乎是一个圆形轨道):

orbita.size = CGSize(width:view.frame.size.width - padding2 , height: view.frame.size.width - padding2)

你的半径是:

let radius:CGFloat = (view.frame.size.width - padding2)/2