Why does my game pause?

Why does my game pause when I press the [ - ] button? It gets really annoying because my game is a MMO, and when you put the window back in focus, it repeats paint(…) like a million times…

Thanks.

Maybe you have some Mnemonic associated with that button in your GUI, or something like that? I can’t think of anything that the - just does.

Well I used NetBeans and created a window with the GUI builder Desktop thing. It just freezes when you minimize it, and when you put it back in focus, it spams paint(…) for how many times paint(…) was missed while it was minimized.

euh when it’s minimised paint isn’t called because well frankly there shouldn’t be anything to paint. Perhaps even the eventqueue polling is stopped too - would probably make sense. I’m not sure how you calculate the paint’s being missed and if your using active rendering or not. If your using active rendering don’t do it on the eventdispatcher thread. if your doing passive rendering - this is expected behaviour and your should do your logic in a separate thread.

Or it could be something else entirely - there’s not much info to go by.

if it’s minimized, will the code still run? just not paint?

Oh, I thought you were talking about the minus key on the keyboard. Nevermind about mnemonics, then.

I have experienced similar problems with minimizing games even in commercial games. for example BF2142 will freeze if you minimize it. wich gya cauase sometime windows does a popup and minimizes the game >:( >:( >:(.

yes, it is really annoying. how do i fix it :\

you could make a window listener and have it listen for minimize and when that happens it loops and does Thread.sleep(however long you see fit) and then have it end when the window is not minimized anymore. this may be ironic cause it is fixing the pausing by pausing. but if you pause it will not expect to repaint so when it wont try and catch up on what it missed.

hope this helps :). If you dont get what I mean jsut ask. I can go into further detail if you wish. Oh eyah and I am not sure if a window minimizing listener is possible. I know iwndow clossing is but…

Good Luck!! :wink:

I put

if(isFocusOwner())

around anything that I don’t want looped when minimized or in my case when you click off the Applet.

But still, it it is minimized, it shouldn’t paint, but it should still do the rest of the collision/ai stuff. :-\

if (isFocusOwner())
draw();

::slight_smile:

That DOES work, but when you click off the game it freezes even if the game window is still visible.

I assume you want it to keep updating for networking purposes? What sort of game timer are you using?

while (true) {
//do game
}

it’s a separate thread

do you need the game ot keep on running while it is minimized or just ot not spazz out on the whole paint hting

I think I can show my solution best with my main loop. It will probably work for you too. I do, however, use active rendering. Repaint might conceivably still be called if you’re using passive rendering, though I don’t know why it would be.

Here’s the code for my main loop:

public void execute() {
	//verify that the loop will continue
	shouldContinueLoop = true;
	
        //stuff here
       ...

	while(shouldContinueLoop) {
		//if the application isn't active, sleep for half a second
		if(!isApplicationActive()) {
			try {
				Thread.sleep(500);
			} catch(InterruptedException exception) {}
				
			continue;
		} //end if the frame isn't active

		//the innards of the loop are here
               ...
	} //end while forever
} //end execute

This isApplicationActive method determines whether the application is “active”. All it does is call Window.isActive() for the main Window of the game. The window is inactive when another application is selected and presumably also when the window is minimized.

Sleeping for half a second (or whatever amount of time you like) is necessary to prevent your program from taking up CPU cycles by checking whether the window is active constantly.

woot I fixed it I just had to make it undecorated and make a fake frame for it :stuck_out_tongue: