简体   繁体   中英

Conversion Type Error CGPoint to CGFloat in Swift

   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

The members of CGPoint have the the type CGFloat , which is a Float on the 32-bit architecture and Double on the 64-bit architecture. Swift does not implicitly convert types. You can either use CGFloat consistently in your code, or add explicit casts:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM