Window focus
by Michael Cordner · in Torque Game Builder · 09/28/2005 (9:02 am) · 7 replies
Quick one, I hope. Is there a callback triggered when a window loses focus? Idea being that i want to call a 'pause' function when a window loses/regains focus.
Thanks!
Thanks!
#2
Thanks
09/29/2005 (4:20 am)
Hi justin, thanks for that. I'm sure I can get a mac person to hack in the corresponding carbon or cocoa (what does it use anyhow?) functionality!Thanks
#3
This will make sure that the game is still running before trying to notify it of anything. I've also modified the first post for anyone that runs across this thread.
Best Regards,
-justin'
09/29/2005 (2:33 pm)
Michael, I noticed a small bug in the code above and I've modified it. The problem occurs when you try to do something with the lost focus callback when the engine is shutting down (it sends a lose focus notification at that point). The modified code is below, it's a slightly altered step 3.if( Game->isRunning() )
Con::executef( 2, "windowFocusChanged", windowActive ? "1" : "0" );This will make sure that the game is still running before trying to notify it of anything. I've also modified the first post for anyone that runs across this thread.
Best Regards,
-justin'
#4
http://www.garagegames.com/mg/forums/result.thread.php?qt=33529
The only difference is that with my version you have to define OnPause and Unpause functions in script, which works fine for me. Now if I can just get streaming audio to pause, I'd be done with this pausing junk!
09/29/2005 (10:49 pm)
Not to beat a dead horse, but I posted a nearly identical solution here awhile back.http://www.garagegames.com/mg/forums/result.thread.php?qt=33529
The only difference is that with my version you have to define OnPause and Unpause functions in script, which works fine for me. Now if I can just get streaming audio to pause, I'd be done with this pausing junk!
#5
Since T2D is mostly event driven, and a lot of these events end up being triggered by stuff like animations finishing, I'm having all sorts of issues trying to 'pause' the game while animations are in the middle of executing. I stop my game's timer, but any animation that's still occurring finished and still triggers any events that result from it's onAnimationEnd. It would be very, very nice if indvidual animations could be 'frozen' somehow, but I'm obviously not sure what the technical implications are (or can you and I'm just missing it?).
Since any viable released game needs to play nice with the desktop, I'd see all of these issues (windowing suspend/resume, freezing animations, pausing audio) as very, very critical. Can anyone indicate if they're being addressed in the next release?
09/30/2005 (2:44 am)
:) Yes, I'm actually finding pausing the game in general to be a bit of a headache. It's okay in trivial cases when nothing is moving (just block input,) but in cases where animations are already underway I can't see any obvious way of stopping them and having them resume from a certain place. Since T2D is mostly event driven, and a lot of these events end up being triggered by stuff like animations finishing, I'm having all sorts of issues trying to 'pause' the game while animations are in the middle of executing. I stop my game's timer, but any animation that's still occurring finished and still triggers any events that result from it's onAnimationEnd. It would be very, very nice if indvidual animations could be 'frozen' somehow, but I'm obviously not sure what the technical implications are (or can you and I'm just missing it?).
Since any viable released game needs to play nice with the desktop, I'd see all of these issues (windowing suspend/resume, freezing animations, pausing audio) as very, very critical. Can anyone indicate if they're being addressed in the next release?
#6
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9385
09/25/2006 (2:37 pm)
I am the necromancer of dead threads. So, I wanted to resurrect this and mention that there is a resource for pausing streaming audio.www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9385
#7
10/17/2006 (11:44 am)
Can the game still runnung while the user drag the window and not pause?
Associate Justin DuJardin
Default Studio Name
While there is not currently support for notifying you of focus change, I took the liberty of writing up a simple focus notification hack that would be useful save for the fact that you'll only get notice of it on windows (since that's all I work on). However, if you'd like to put it in there, perhaps some Mac and Linux gurus can duplicate this code to work on their platforms! Quite simple really, just follow the steps below!
Step 1 - open up (in the engine) - engine/platformWin32/winWindow.cc
Step 2 - find the lines
case WM_ACTIVATE: windowActive = LOWORD(wParam) != WA_INACTIVE;Step 3 - Right below the windowActive line, add the following line
if( Game->isRunning() ) Con::executef( 2, "windowFocusChanged", windowActive ? "1" : "0" );Step 4 - Recompile your engine
Step 5 - Add a script function to your game that will receive this callback. I've once again taken the liberty of writing up a simple one for you!
function windowFocusChanged( %focused ) { if (%focused ) echo("WE'VE GOT FOCUS... YES!!!"); else echo("WE LOST OUR FOCUS OH NO!"); }Step 6 - Enjoy!
---------------------------------
Hope this helps! :)
Best Regards,
-justin'