0

enter image description here

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

Dakata
  • 1,227
  • 2
  • 14
  • 33

1 Answers1

2

Having a look here, I can't see an overload that takes a CGFloat. simd.clamp takes either, float2, float3, float4, double2, double3 or double4.

To use your func clamp(value:, min:, max:), call it this way :

destX = clamp(value: destX, min: ballRadius, max: frame.width - ballRadius)
ielyamani
  • 17,807
  • 10
  • 55
  • 90