I explicitly cast the type between them, but the error is still there
var destX:CGFloat = 5.0
func clamp(value: CGFloat, min: CGFloat, max: CGFloat) -> CGFloat {
if value > max {
return max
}
else if value < min {
return min
}
return value
}
override func update(_ currentTime: TimeInterval) {
let ballRadius: CGFloat = 10
destX = simd.clamp(destX, min: ballRadius, max: frame.width - ballRadius) as CGFloat
let destXAction = SKAction.moveTo(x: destX, duration: 0.1)
self.main.run(destXAction)
Here is the code