Swift error: "cannot invoke >= with argument of list type (@lvalue CGPoint, CGPoint)"?
Swift error: "cannot invoke >= with argument of list type (@lvalue CGPoint, CGPoint)"?
我正在尝试编写一个 if 语句,说明如果 block1
的位置超过某个点,block3
是否会发生这种情况。但是,当我尝试使用 >=
进行比较时,出现错误:"cannot invoke >= with argument of list type (@lvalue CGPoint, CGPoint)"
代码如下:
if block1.position >= CGPoint(self.size.width * 0.35,700) {
block3.hidden = false
block3.runAction(moveDownLeft)
}
block1 是一个 SKSpriteNode。
CGPoint 是一个结构体。 CMD-点击查看定义:
struct CGPoint {
var x: CGFloat
var y: CGFloat
}
比较单个元素就大功告成了。
// if p2 > p1 then p2 is above p1 and p2 is on the right of p1
func >=(lhs: CGPoint, rhs: CGPoint) -> Bool {
return lhs.x >= rhs.x && lhs.y >= rhs.y
}
// if p2 < p1 then p2 is below p1 and p2 is on the left of p1
func <=(lhs: CGPoint, rhs: CGPoint) -> Bool {
return lhs.x <= rhs.x && lhs.y <= rhs.y
}
也发布在 this page
我正在尝试编写一个 if 语句,说明如果 block1
的位置超过某个点,block3
是否会发生这种情况。但是,当我尝试使用 >=
进行比较时,出现错误:"cannot invoke >= with argument of list type (@lvalue CGPoint, CGPoint)"
代码如下:
if block1.position >= CGPoint(self.size.width * 0.35,700) {
block3.hidden = false
block3.runAction(moveDownLeft)
}
block1 是一个 SKSpriteNode。
CGPoint 是一个结构体。 CMD-点击查看定义:
struct CGPoint {
var x: CGFloat
var y: CGFloat
}
比较单个元素就大功告成了。
// if p2 > p1 then p2 is above p1 and p2 is on the right of p1
func >=(lhs: CGPoint, rhs: CGPoint) -> Bool {
return lhs.x >= rhs.x && lhs.y >= rhs.y
}
// if p2 < p1 then p2 is below p1 and p2 is on the left of p1
func <=(lhs: CGPoint, rhs: CGPoint) -> Bool {
return lhs.x <= rhs.x && lhs.y <= rhs.y
}
也发布在 this page