gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:34:26 24 4
gpt4 key购买 nike

我正在制作一个球沿着路径运动的游戏,实际上这只是一种错觉,因为场景是旋转的。问题在于,在某些设备中,球会离开屏幕,而在其他设备中,半径看起来很小。我试图使半径相等 (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

关于swift - 如何缩放半径以适应所有设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38208175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com