我试图通过使对象通过分段控件上的变量更快或更慢地移动来改变游戏的长度,但是我遇到了错误:表达式类型'@lvalue CGPoint'在没有更多上下文的情况下是模棱两可的。
@IBAction func control(sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0{
//variable changes in order to change the distance "purple" moves
var length: Int = 10;
} else if sender.selectedSegmentIndex == 1{
var length: Int = 20;
} else{
var length: Int = 30;
}
}
@IBAction func Red(sender: AnyObject) {
var l: Int;
if self.Purple.center.y > self.TopFinish.center.y && self.Purple.center.y <
self.Finish.center.y && y==0{
UIImageView.animate(withDuration:0.75, delay: 0, options: .curveLinear,
animations: {
//i got the error below:
self.Purple.center.y += length;
}, completion: nil)
}
if self.Purple.center.y >= self.Finish.center.y{
Label.text="Red Wins!"
Restart.isHidden=false;
self.Purple.center.y = self.Finish.center.y
y=1
}
}
答案 0 :(得分:0)
您从未在lenght
中定义func Red
您需要制作一个全局变量或在函数内部定义它。