Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualslicer4ever

Posted 09 February 2013 - 06:54 PM

why are you calling run after you setIsRunning(true)?(now your in a loop inside the input function)

 

if that's not the problem, idk because you barely posted any real code.

 

what we need to see is:

 

Initialization code

--Main game loop(is this controlled by "isRunning", because if so, setting it to false should break the loop.)

---Where you check for input(is this inside your main loop, which is controlled by the "isRunning" flag?)


#3slicer4ever

Posted 09 February 2013 - 06:54 PM

why are you calling run after you setIsRunning(true)?(now your in a loop inside the input function)

 

if that's not the problem, idk because you barely posted any real code.

 

what we need to see is:

 

Initialization code

--Main game loop(is this controlled by "isRunning", because if so, setting it to false should break the loop.(

---Where you check for input(is this inside your main loop, which is controlled by the "isRunning" flag?)


#2slicer4ever

Posted 09 February 2013 - 06:51 PM

why are you calling run after you setIsRunning(true)?(now your in a loop inside the input function)

 

if that's not the problem, idk because you barely posted any real code.


#1slicer4ever

Posted 09 February 2013 - 06:51 PM

The idea was making the gameLoop false to pause the game and unpause the game by making the gameLoop true again. It was able to pause and unpause once before the only way to close the game was to use Eclipse's terminate button instead of the x button in the top corner of the game window. 
 
public class Game extends Canvas implements KeyListener{
 
      private boolean isRunning;   
      
      public static void main(String[] args){
        getInstance().run();
      }   
      
      // Singleton pattern get instance
    public static Game getInstance(){
        if (instance == null){
            instance = new Game();
            
        }
        return instance;
        
    }  
 
      private Game(){  
      isRunning = true;  
      }

 
      public void run(){
         // basic game loop
         while(isRunning){
         // draws objects here
      }
 
          @Override
    public void keyPressed(KeyEvent e) {
        // TODO Auto-generated method stub
        switch (e.getKeyCode()) 
        {
        
        // pause the game 
        case (KeyEvent.VK_P):
            
        getInstance().setIsRunning(false);
                    
        break;
        // unpause the game
        case (KeyEvent.VK_U):
 
        getInstance().setIsRunning(true);
        run();
 
        break;
        }
    }
 
}

 

why are you calling run after you setIsRunning(true)?(now your in a loop inside the input funcion)

 

if that's not the problem, idk because you barely posted any real code.


PARTNERS