2
我正在構建一個精靈套件遊戲,並在我的更新方法中,我有幾個if語句檢查節點速度。我遇到的問題是用聲明檢查x和y速度是否等於0.在遊戲中有3個球體,我正在檢查速度。現在,如果if語句找到至少一個x和y速度等於0的orb,但是我希望它只有在所有orbs滿足語句的情況下才執行。滿足如果語句與enumerateChildNodesWithName的所有節點
我該怎麼做呢?提前致謝!
override func update(currentTime: CFTimeInterval) {
centerOrbs()
orbLayer.enumerateChildNodesWithName("player", usingBlock: { node, _ in
if let orb = node as? Orb {
orb.checkObjects()
let rotation1 = orb.physicsBody?.velocity.dy
let rotation2 = orb.physicsBody?.velocity.dx
orb.zRotation = atan2(rotation1!, rotation2!)
if (orb.physicsBody?.velocity.dx == 0 && orb.physicsBody?.velocity.dy == 0) {
self.compareOrbPositions()
}
if (orb.physicsBody?.velocity.dx != 0 || orb.physicsBody?.velocity.dy != 0) {
self.waitForOrbsToStop()
}
}
})
let count = String(moveCount)
moveCountLabel.text = NSString(string: "Moves: \(count)")
}
@Martin - 這是我一直在尋找,謝謝。 – Justin 2014-11-24 18:45:20