Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Is there a way to detect when the player tabs out of the game? I'm having a problem where sounds will keep playing but the timer stops when the game is tabbed out, leading to everything not being synced up correctly. |
||||
|
ccbRegisterKeyUpEvent for ALT TAB keys and then call ccbStopSound. |
||||
|
Based on gazzauk's suggestion, here is a non-optimal script-based workaround for the issue described by nazrin6. The script is small & very basic. Further adjustments may be necessary. If someone has a better workaround, please post it. A real solution for the problem might involve a modification of how the engine handles sound-playback when the game window loses/regains focus. Like "pausing" & "unpausing" the audio thread or internally calling ccbPauseAllSounds(). Problem description: When the CopperCube game window loses focus, the game appears to enter a "sleep" mode, halting the game-loop & scripts but active sounds continue to play. What this script-setup does: When the ALT key or the WINDOWS key is pressed (which usually happens when the player wants to "leave" the game window), ALL sounds are paused. ALL sounds are resumed when the keys are no longer held down and the game-loop runs normally - this usually happens when the player returns to the game window and the game wakes up from "sleep" mode. IMPORTANT: - Works for the Windows exe target. Tested in windowed & fullscreen mode. - Pauses / unpauses ALL sounds - via ccbPauseAllSounds(). Known issues: - CTRL+ALT+DEL may exit the window and reselect it in the background, circumventing this workaround. - In fullscreen: Holding ALT down without pressing TAB will pause all sounds while the game keeps running. Uncomment the lines with "ccbSetGameTimerSpeed()" to pause/unpause physics & movement as a partial workaround for this problem. - Any other cool methods that allow you to "leave" the game window are not captured by this script. - If the user repeatedly tabs out & returns to the game, audio may still get out of sync as the small timing differences caused by the cooldown-counter would probably accumulate. Notes: - On my system, TAB (keyCode = 9) is never registered by the engine when ALT+TAB is pressed. - In windowed mode: Pressing ALT triggers the game window to become inactive. This does not happen in fullscreen mode. - Internally, the engine appears to use the GetActiveWindow()-function in "user32.dll" to check if the game window is active. How to use this script: - Select the root scene node - Add a behavior "Before first drawing do something" - Check: AlsoOnReload - Action: Execute Javascript Javascript:
|
||||
|
|