How do I make a while loop that runs in the background?

Inside my delayWithSeconds function are there the DispatchQueue
function

No. I believe that @kirilltitov is suggesting that you use DispatchQueue to run your game loop, something like this:

let queue = DispatchQueue(label: "game loop")
queue.async {
    while running {
        … your code here …
    }
}

Generally I recommend that you avoid using Dispatch for this but instead create a dedicated thread. I explain why in this post.

Regardless of how you implement this, I agree with @zoul that you really need to get your head around the core concept of the game loop.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

3 Likes