我目前遇到一个奇怪的浮点问题。有人可以解释吗?
import SpriteKit
let height: CGFloat = 20.0
let width: CGFloat = 150.0
let shapeNode: SKShapeNode = SKShapeNode(rectOf: CGSize(width: width, height: height))
print(shapeNode.frame.size.width, shapeNode.frame.size.height) //152.6999969482422 22.700000762939453
这是您想要的:
import SpriteKit
let height: CGFloat = 20.0
let width: CGFloat = 150.0
let shapeNode: SKShapeNode = SKShapeNode(rectOf: CGSize(width: width, height: height))
shapeNode.isAntialiased = false
shapeNode.lineWidth = 0
print(shapeNode.frame.size.width, shapeNode.frame.size.height) // 150.0 20.0\n
记住:https://developer.apple.com/documentation/spritekit/skshapenode
...是在运行时动态栅格化形状以产生清晰的细节和平滑的边缘。