2017-07-15 12 views
0

私はさまざまな定義された位置を経由してramdonlyにジャンプするように鹿を作ろうとしています。アクションのためにループを一時停止する - Swift:Sprite Kit

func deerJumping() { 
    // The different locations are arranged ramdonly 
    var places: [CGFloat] = [1124, 852, 1540, 1908, 628, 1736, 392].shuffled() 
    //Then the for loop with the actions (jumps) between this positions 
    for posc in places { 
     //SKAction for the up and down 
     //SKAction for the displacement left or right 
     //Code for the deer to face the direction of the jump 
     //Then run the action: 
     deer.run(SKAction.group([jump, move])) 
    } 
} 

問題は、配列の次の位置に移動する前にループがアクションを完了するのを待っていないことです。

このPause and Resume a for Loop質問があります。ループの中にNSOperationインスタンスを作成してNSOperationQueueに追加しようとしていますが、悲しいことに私は初心者です。私のコードにどのように適用するのか分かりません。

ご協力いただければ幸いです。

答えて

1

何も待っていない理由は、すべての操作を同時に実行するためです。あなたは

は今、私はあなたが私を助けることができる前に、その1について詳しく説明する必要があるとしている、あなたが一時停止し、forループを再開したい理由はわかりません
func deerJumping() { 
    // The different locations are arranged ramdonly 
    var places: [CGFloat] = [1124, 852, 1540, 1908, 628, 1736, 392].shuffled() 
    //Then the for loop with the actions (jumps) between this positions 
    var actions = [SKAction]() 
    for posc in places { 
     //SKAction for the up and down 
     //SKAction for the displacement left or right 
     //Code for the deer to face the direction of the jump 
     //Then run the action: 
     actions.append(SKAction.sequence([jump, move])) 
    } 
    var deerRunning = SKAction.sequence(action) 
    deer.run(deerRunning) 

} 

アクションの配列を作成したいと順序で実行しますあなたは出て行く。

+0

ありがとうKnightOfDragon。私はそれが動作すると思う! :) – Sersiego

+0

私は次の位置に巡回する前にアクションを実行する時間を作るためにループを一時停止したかったのです。 – Sersiego

+0

私はあなたにフォローしていません。 forループを一時停止すると何もしません – Knight0fDragon

関連する問題