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

时间:2016-07-05 16:17:11

标签: swift sprite-kit size scale

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

  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
}

1 个答案:

答案 0 :(得分:0)

如果你的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