Game Development Community

Request - Pause audio

by Conor O Kane · in Torque Game Builder · 06/07/2008 (12:28 am) · 2 replies

Please add the ability to pause audio in script. I realize there are some engine modifications released that can do this, but it really should be something available to non-pro license holders.

#1
07/16/2008 (11:46 am)
Conor, put this code in game.cs and let me know if it works for you:

//---------------------------------------------------------------------------------------------
// Pause game when player navigates away from game window
//    -isFocused: 0=game window not focus, 1=game window is focus
//---------------------------------------------------------------------------------------------
function onWindowFocusChange(%isFocused)
{
   // pause game
    if (!%isFocused)
        pauseWindow(1);
        
   // unpause game
    else
        pauseWindow(0);
}

//---------------------------------------------------------------------------------------------
// Pause or unpause the game (when alt+tab away from game window).
//---------------------------------------------------------------------------------------------
function pauseWindow(%state)
{      
    %scene = Scenewindow2d.getSceneGraph();       
    %result = (%state == 1) ? true : false;
    
    // pause game (only if the player hasn't paused the game)
    if (!$pauseingame)
    {
      %scene.setScenePause( %result ); 
      $paused = %state;
    }
    
    // turn music off when paused
    if (%state)
      alxSetChannelVolume($GuiAudioType, 0);
    
    // turn music on when upaused (and music option on)
    else if ($music)
      alxSetChannelVolume($GuiAudioType, 1);
}

Note: you can call pauseWindow(%state) from anywhere in your script. This example pauses the game when you navigate away from the game on your computer.
#2
10/11/2008 (7:49 pm)
Thanks Amanda, but rather than just silencing the audio I'd really like for it to pause and resume at the same point. This is important for games where the music is synced to the action. The inability to pause the music means that no pause feature can be implemented at all for games of this type.

The issue has been solved for those with the source code

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9385

It would be great if this was integrated into the engine.