转换类型错误CGPoint到Swift中的CGFloat

时间:2014-07-04 10:47:53

标签: ios swift sprite-kit

   var _deltaTime = NSTimeInterval()

   var _pointsPerScndSpeed = Double()

   var bgVelocity: CGPoint = CGPointMake(_pointsPerScndSpeed, 0.0)

      //Cannot convert the expression's to type 'CGFloat'

     var amToMove:CGPoint = CGPointMake(bgVelocity.x * _deltaTime, bgVelocity.y * _deltaTime)

       //Could not find an overload for '*' that accepts the supplied Arguments

1 个答案:

答案 0 :(得分:1)

CGPoint的成员的类型为CGFloat,在32位上为Float 体系结构和64位体系结构上的Double。 Swift不会隐式转换类型。你可以使用CGFloat 始终在您的代码中,或添加显式强制转换:

var bgVelocity: CGPoint = CGPointMake(CGFloat(_pointsPerScndSpeed), 0.0)
var amToMove:CGPoint = CGPointMake(bgVelocity.x * CGFloat(_deltaTime), bgVelocity.y * CGFloat(_deltaTime))