好的,我很难接受这个。出于某种原因,在尝试找出向量时,我无法在CGPoint值中使用x坐标。看看下面的示例游乐场代码:
var lastTouch: CGPoint? = nil
let myPoint: CGPoint = CGPoint(x:0, y:0)
let impulseVector: CGVector = CGVector(lastTouch.x - 20, 0) //returns error
错误消息特别针对" .x"并说" CGPoint?没有名为" x"的成员有谁知道我怎么解决这个问题?
以下是我要将其应用于以下内容的片段:
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
if let touch = lastTouch {
let impulseVector: CGVector = CGVector(lastTouch.x - myShip.position.x, 0)
myShip.physicsBody.applyImpulse(impulseVector)
}
}