How to make a boss key

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
negester
Prole
Posts: 9
Joined: Fri Nov 18, 2011 4:41 am

How to make a boss key

Post 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?
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: How to make a boss key

Post 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 ;)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests