我试图在touchesBegan时向左移动精灵,然后在下次用户触摸时向右移动。
我已经看到了一些我觉得可以完美运行的代码但是我不太清楚如何定义" isMovingleft"
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
ship.removeAllActions()
if isMovingleft == true {
let left = SKAction.moveBy(x: 500, y: 0, duration: 5)
ship.run(left)
}
else {
let right = SKAction.moveBy(x: -500, y: -900, duration: 5)
ship.run(right)
}
isMovingleft = !isMovingleft
}
答案 0 :(得分:1)
endRendering