[英]Swift "Cannot invoke '-=' with argument list of type '(@lvalue CGFloat, $T7)'
Can someone please explain to me why I am getting this error message when I try to run this code: 有人可以向我解释为什么在尝试运行此代码时为什么收到此错误消息:
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.xScale = 0.5
sprite.yScale = 0.5
sprite.position = location
self.addChild(sprite)
var dt: Float = 1.0/60.0
sprite.position.x -= 100.0*dt;
The error message appears on the last line by the way 错误消息出现在最后一行
you need to change dt
to CGFloat
because sprite.position.x
have type of CGFloat
您需要将dt
更改为CGFloat
因为sprite.position.x
具有CGFloat
类型
var dt: CGFloat = 1.0/60.0
in Swift, arithmetic operators require both operands have same type 在Swift中,算术运算符要求两个操作数具有相同的类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.