Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Why does my game pause?  (Read 3104 times)
0 Members and 1 Guest are viewing this topic.
Offline Renoria

Junior Member




...


« Posted 2009-01-25 04:11:04 »

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.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #1 - Posted 2009-01-25 06:19:41 »

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.

See my work:
OTC Software
Offline Renoria

Junior Member




...


« Reply #2 - Posted 2009-01-25 06:32:42 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr_Light

Senior Member




shiny.


« Reply #3 - Posted 2009-01-25 07:07:06 »

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.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Renoria

Junior Member




...


« Reply #4 - Posted 2009-01-25 07:24:12 »

if it's minimized, will the code still run? just not paint?
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2009-01-25 10:57:32 »

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

See my work:
OTC Software
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #6 - Posted 2009-01-25 14:26:46 »

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  Angry Angry Angry.
Offline Renoria

Junior Member




...


« Reply #7 - Posted 2009-01-25 15:09:11 »

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

JGO Coder


Medals: 5



« Reply #8 - Posted 2009-01-25 15:21:45 »

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 Smiley. 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
Offline Corvinex

Senior Member


Projects: 1


Work Hard, Go Pro.


« Reply #9 - Posted 2009-01-25 18:54:34 »

I put
1  
if(isFocusOwner())
around anything that I don't want looped when minimized or in my case when you click off the Applet.

"Do what you love and you'll never work a day in your life."
Android: Pac-Ball
Web Applet: Virus Effect
Old Games
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Renoria

Junior Member




...


« Reply #10 - Posted 2009-01-26 01:23:41 »

But still, it it is minimized, it shouldn't paint, but it should still do the rest of the collision/ai stuff.  Undecided
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #11 - Posted 2009-01-26 03:58:00 »

But still, it it is minimized, it shouldn't paint, but it should still do the rest of the collision/ai stuff.  Undecided
if (isFocusOwner())
draw();

 Roll Eyes


See my work:
OTC Software
Offline Renoria

Junior Member




...


« Reply #12 - Posted 2009-01-26 05:40:00 »

if (isFocusOwner())
draw();

 Roll Eyes



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

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #13 - Posted 2009-01-26 08:23:03 »

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?

See my work:
OTC Software
Offline Renoria

Junior Member




...


« Reply #14 - Posted 2009-01-26 08:35:35 »

while (true) {
 //do game
}

it's a separate thread
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #15 - Posted 2009-01-26 17:30:51 »

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

Senior Member





« Reply #16 - Posted 2009-01-27 00:05:02 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
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.
Offline Renoria

Junior Member




...


« Reply #17 - Posted 2009-01-29 08:24:44 »

woot I fixed it I just had to make it undecorated and make a fake frame for it Tongue
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!