Page 1 of 1

How to make a boss key

Posted: Fri Nov 25, 2011 11:54 am
by negester
You know what I mean. When you hit it, game sounds stop instantly and the game vanishes from your screen. Not necessary to display the old bogus spreadsheet: your desktop, apart from the love2d game, looks absolutely kosher, surely.

Hitting your window manager's iconify button hides the screen, but that is not much use if the Klingons can still be heard firing nonstop on the earphones that you are forced to take off. Attempting two actions is futile. Your boss key must do everything.

I do this:

Code: Select all

 function love.keypressed(key)  
   if key=='q' then love.audio.setVolume(0); love.graphics.setMode(1,1) end
   if key=='r' then love.audio.setVolume(1); love.graphics.setMode(800,600) end
end
Only problem is, restoring is tricky. it's quite hard to give the game focus so it can respond to that 'r'.

But surely this is a solved problem? Many existing games must have the feature?

Re: How to make a boss key

Posted: Fri Nov 25, 2011 1:00 pm
by Ellohir
You can use "love.focus(f)" so sound deactivates when it looses focus. Something like

Code: Select all

function love.focus(f) 
        if gameIsPaused then
                -- game is resumed
                love.audio.setVolume(0)
        else
                -- game lost focus
                love.audio.setVolume(1)
        end
        -- change game status
        gameIsPaused = not f 
end
And then on love.update

Code: Select all

function love.update(dt)
     -- if we are paused we are done
     if gameIsPaused then return end   
That way you can Alt+Tab quickly deactivating sound and gameplay ;)