But since this is a loop that runs forever until the player dies. The script can't go through under this piece of code, if that makes sense. So my question is how do I make this go forever and the compiler can see the code under the loop.
The loop you’re talking about is usually called the game loop and it’s a huge topic with many possible solutions. Here’s one nice article about it. One important trick is to split the rendering from updating the game state, so you would have something like:
var lastTime = CFAbsoluteTimeGetCurrent()
var state = GameState(…)
while running {
let now = CFAbsoluteTimeGetCurrent()
// Recalculate game state according to how much real time has elapsed
state.update(timeDelta: now - lastTime)
// Render the state to the screen
renderState(state)
}
I suggest that you research writing game loops on iOS.
instead of running several time it just plays its ones
I’m not entirely sure what this means, but I think you’re saying that the game loop exits after one iteration. If so, it’s hard to say what’s going on without seeing the logic that updates isGameStarted. My recommendation is that you step through the code to see when isGameStarted changes.
btw Earlier I recommended not to use Dispatch for your game loop, but instead use a thread. There’s a snippet showing this in the other post I referenced.