【发布时间】:2016-12-16 07:31:32
【问题描述】:
我有一个游戏,有 3 个SKSpriteNodes,用户可以使用touchesBegan 和touchesMoved 在其中移动。但是,当用户移动nodeA 并通过另一个名为nodeB 的节点时,nodeB 会跟随nodeA 等等。
我创建了一个SKSpriteNodes 数组,并使用for-loop 让生活更轻松。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let nodes = [nodeA, nodeB, nodeC]
for touch in touches {
let location = touch.location(in: self)
for node in nodes {
if node!.contains(location) {
node!.position = location
}
}
}
}
一切正常,除非nodeA 移动并与nodeB 交叉路径,nodeB 跟随nodeA。
我怎样才能使当用户移动nodeA 和nodeA 通过nodeB 时nodeB 不会跟随nodeA。
【问题讨论】:
标签: sprite-kit touchesbegan touchesmoved