在我的場景包遊戲中,節點隨機添加到場景中。這些節點沿一個方向行進,直到它們超過所需的最終位置,然後它們將被移除。他們可以向上,向下,向左和向右行進。 (我使用node.runAction(SCNAction.repeatActionForever(SCNAction.moveBy(...
)刪除節點導致保留週期
下面是我用來檢測節點何時超過它的結束位置,以便它們可以被刪除。
我遇到的問題是,雖然這個工程,由於某種原因,它造成了保留週期,SCNActionMove和SCNActionRepeat。
我發現避免這種情況的唯一方法是在遊戲結束後立即在for循環中刪除所有節點,但這並不理想,因爲遊戲可以長時間播放。
謝謝!
func renderer(renderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {
// If any nodes have been spawned
if spawnedNodeArray.count > 0 {
// Get the first spawned node
let node = rootNode.childNodeWithName(spawnedNodeArray[0].nodeName, recursively: true)!
// If node is moving RIGHT, check if node has reached end position
if spawnedNodeArray[0].Direction == "RIGHT" {
// If node has reached past end position...
if node.position.x >= Float(spawnedNodeArray[0].EndXPos) {
node.removeAllActions()
node.removeFromParentNode()
spawnedNodeArray.removeAtIndex(0)
}
}
// If node is moving LEFT, check if node has reached end position
else if spawnedNodeArray[0].Direction == "LEFT" {
// If node has reached past end position...
if node.position.x <= Float(spawnedNodeArray[0].EndXPos) {
node.removeAllActions()
node.removeFromParentNode()
spawnedNodeArray.removeAtIndex(0)
}
}
// If node is moving DOWN, check if node has reached end position
else if spawnedNodeArray[0].Direction == "DOWN" {
// If node has reached past end position...
if node.position.z >= Float(spawnedNodeArray[0].EndZPos) {
node.removeAllActions()
node.removeFromParentNode()
spawnedNodeArray.removeAtIndex(0)
}
}
// If node is moving UP, check if node has reached end position
else if spawnedNodeArray[0].Direction == "UP" {
// If node has reached past end position...
if node.position.z <= Float(spawnedNodeArray[0].EndZPos) {
node.removeAllActions()
node.removeFromParentNode()
spawnedNodeArray.removeAtIndex(0)
}
}
}
}
偉大的建議,我會試試這個。謝謝! – P3rry