Skip to content

Commit

Permalink
fix: avoid delay when resuming game
Browse files Browse the repository at this point in the history
and unpause when starting new game
  • Loading branch information
literalpie committed Mar 5, 2022
1 parent c8a0d1d commit 123c91c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Wonky Blocks/Support/GameState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class WonkyGameState: ObservableObject, JoystickState {
score = 0
lineCount = 0
level = 1
paused = false
gameOver = false
newHighScore = false
activeTet = nextTet
Expand Down
6 changes: 5 additions & 1 deletion Wonky Blocks/UI/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ struct GameView: UIViewControllerRepresentable {
_ uiViewController: WonkyGameViewController,
context: Context
) {
uiViewController.spriteKitView.isPaused = gameState.paused
// pausing the scene causes a delay when unpausing. We'll stop the phyiscs instead to avoid this.
// unfortunately, this means there will be consistent CPU usage while the app is running.
// I tried pausing only when the window is inactive,
//but macOS only counts as inactive when you minimize - and spritekit already pauses when this happens.
uiViewController.spriteKitView.scene?.physicsWorld.speed = gameState.paused ? 0.0 : 1.0
}

static func dismantleUIViewController(
Expand Down

0 comments on commit 123c91c

Please sign in to comment.