ディスパッチキューまたはタスクハンドラが迅速に機能する方法を理解できませんでした3:私はパフォーマンス上の問題があり、複数のブロックを実行したいすべてのブロックが完了するまで関数を終了するのを待ちます。私は単純にブロックを非同期でバックグラウンドで実行しようとしましたが、非同期キューで管理されている同じ配列またはenumerateChildNodes(...)で列挙されているため、 "xxxが変わる間にxxxを使用しようとします"私はSpriteKitノードの最小化を管理してfpsを改善しようとしています。ここで私は、並列に実行したいコードブロックの一例であり、それらは待つ:スウィフト3で同時にコードブロックを実行する機能が完了するまで待つ
func determinePlatformNodesToUse() {
// Code Block 1:
for platform in platformArray {
addPlatformNode(platform, leftDistance: leftDistance, rightDistance: rightDistance)
}
// Also part of Code Block 1:
// resort the platform nodes to guarantee position sequence
currentPlatformNodeArray.sort(by: { $0.position.x < $1.position.x })
// Code Block 2:
for character in characterArray {
if character.type == CharacterType.Enemy {
addCharacterNode(character, leftDistance: leftDistance, rightDistance: rightDistance)
}
}
// Code block 3
// put all the enemies into an array for update processing will be added in addCharacterNode
currentMotionEnemyNodeArray.removeAll()
// Also part of Code block 3
foregroundNode.enumerateChildNodes(withName: CharacterType.Enemy.rawValue, using: {
(node, stop) in
if let enemy = node as? CharacterNode {
if enemy.motionType != .Stand { // dont use .Stand as they dont have motion
self.currentMotionEnemyNodeArray.append(enemy)
}
}
})
// Code Block 4
for actionSceneObject in actionSceneObjectArray {
addActionSceneObjectNode(actionSceneObject, leftDistance: leftDistance, rightDistance: rightDistance)
}
// At this point, wait until all blocks 1-4 above have finished
// Run blocks 5 - 8 code in all in parallel
// wait until blocks 5 - 8 have finished and then leave the function
}
こんにちは、問題が解決された場合は教えてください – KrishnaCA