我正在尝试在游戏中创建一个比例量,偶尔数学等式会对amountToScale变量产生错误的答案。以下是我的代码返回的答案,如您所见,686 / newDownObject.size.width,即505不等于1.579。为什么会这样?任何帮助表示赞赏!
以下是我的代码产生的答案:
身高:545.0
宽度:505.0
比例:1.57981651376147
新身高:861.0
新宽度:797.807339449541
if newDownObject.size.width >= newDownObject.size.height {
let amountToScale = 686 / newDownObject.size.width
let scale = SKAction.scale(by: amountToScale, duration: 0.25)
newDownObject.run(scale)
let newHeight = newDownObject.size.height * amountToScale
let newWidth = newDownObject.size.width * amountToScale
let scaleBackground = SKAction.resize(toWidth: newWidth + 14, height: newHeight + 14, duration: 0.25)
newDownObjectBackground.run(scaleBackground)
print("height : \(newDownObject.size.height)")
print("width: \(newDownObject.size.width)")
print("scale: \(amountToScale)")
print("new height : \(newHeight)")
print("new width: \(newWidth)")
}