•      Sign In
• Create Account

We're offering banner ads on our site from just \$5!

### #Actualwarnexus

Posted 09 February 2013 - 11:12 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?)

because my approach was to pause the game. The only way to do it is to break out of the gameLoop. If I unpause the game, I need to call the run method which execute the game loop to keep things drawing again. the run method needs to be called by the programmer. the key events are in the keyPressed method of the Game class since the Game class will be responsible for controlling the pause/unpause nature of the game.

Are you sure you saw my code?

think about what it means to start an infinite loop inside your input logic thread.  and as far as i can see, that infinite loop does not check your input.

so yes, we need to see more code(unless my above assumption is correct, and that is why you can only pause/unpause once)

insead of doing:

void run(void){
while(isRunning){
}
}


try:

void run(void){
while(!isDone){
if(isRunning){
//game logic here
}
}


why is void a parameter and is not given a data type? I posted my game loop below since I cannot longer edit my initial post.

public void run(){
// basic game loop
while(isRunning){
// calculate the time since the last loop
long milliseconds = System.currentTimeMillis() - lastTick;
lastTick = System.currentTimeMillis();

// set the focus to the panel
panel.requestFocus();

// get graphics context
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
clearBuffer(g);

// update all game items
for(GameComponent component : gameObjects){
component.update(milliseconds);

}

// handle the dynamic objects
addNewGameComponents();
removeOldGameComponents();

// draw all game items
for(GameComponent component: gameObjects){
component.draw(g);
}

/* do a bounding box collision of the laser with the
*  oneEye monster's bounding box every game loop
*  which is basically every time the game redraws
*  itself.
*  Collision test applies to ALL laser being drawn on screen!
*
*  The easiest way is to check every instance of type Laser in the
*  ArrayList and tell them to do monster collision detection
*/

// laser check for every OneEye monsters in the ArrayList
for(GameComponent component: gameObjects){
if(component instanceof Laser)
{
((Laser) component).checkMonsterCollision(gameObjects);

}
if(component instanceof OneEyeSlashSkill)
{
((OneEyeSlashSkill) component).checkShipCollision(gameObjects);

}

}

flipBuffer(g);

// pause for a bit so we don't consume 100% CPU

try { Thread.sleep(10); } catch (Exception e) {}

}
}

ok, so i'm fairly certain(note: i've used little java, so i might be wrong in how java handle's things) the problem is as i described, you are calling run inside your input logic, this means that you essentially never get back to check input again.

the void inside the run is just indicating that their are no parameters to pass to the function(as epicpunnum said), so you can freely think of run() and run(void) as the same thing.

in short, don't break the loop inside run, just do a conditional check inside the loop that if(isRunning==true), and put your logic inside that.

alternatively, you coud do:

void run(){
while(!isDone){
if(!isRunning) continue; //goes back to the beginning of the loop.
//your code here!
}
};


basically, your core problem is that you call run() inside your input code, instead you need to re-think how you manage your main loop with pause/unpause.

what do you mean by input logic? on a side note, isn't a game loop consider to be an infinite loop if runs constantly to do handling tasks like drawing objects and testing collisions?

but the game loop keeps running and the game class has keylisteners added. It is not that I removed the listeners.

### #2warnexus

Posted 09 February 2013 - 11:09 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?)

because my approach was to pause the game. The only way to do it is to break out of the gameLoop. If I unpause the game, I need to call the run method which execute the game loop to keep things drawing again. the run method needs to be called by the programmer. the key events are in the keyPressed method of the Game class since the Game class will be responsible for controlling the pause/unpause nature of the game.

Are you sure you saw my code?

think about what it means to start an infinite loop inside your input logic thread.  and as far as i can see, that infinite loop does not check your input.

so yes, we need to see more code(unless my above assumption is correct, and that is why you can only pause/unpause once)

insead of doing:

void run(void){
while(isRunning){
}
}


try:

void run(void){
while(!isDone){
if(isRunning){
//game logic here
}
}


why is void a parameter and is not given a data type? I posted my game loop below since I cannot longer edit my initial post.

public void run(){
// basic game loop
while(isRunning){
// calculate the time since the last loop
long milliseconds = System.currentTimeMillis() - lastTick;
lastTick = System.currentTimeMillis();

// set the focus to the panel
panel.requestFocus();

// get graphics context
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
clearBuffer(g);

// update all game items
for(GameComponent component : gameObjects){
component.update(milliseconds);

}

// handle the dynamic objects
addNewGameComponents();
removeOldGameComponents();

// draw all game items
for(GameComponent component: gameObjects){
component.draw(g);
}

/* do a bounding box collision of the laser with the
*  oneEye monster's bounding box every game loop
*  which is basically every time the game redraws
*  itself.
*  Collision test applies to ALL laser being drawn on screen!
*
*  The easiest way is to check every instance of type Laser in the
*  ArrayList and tell them to do monster collision detection
*/

// laser check for every OneEye monsters in the ArrayList
for(GameComponent component: gameObjects){
if(component instanceof Laser)
{
((Laser) component).checkMonsterCollision(gameObjects);

}
if(component instanceof OneEyeSlashSkill)
{
((OneEyeSlashSkill) component).checkShipCollision(gameObjects);

}

}

flipBuffer(g);

// pause for a bit so we don't consume 100% CPU

try { Thread.sleep(10); } catch (Exception e) {}

}
}

ok, so i'm fairly certain(note: i've used little java, so i might be wrong in how java handle's things) the problem is as i described, you are calling run inside your input logic, this means that you essentially never get back to check input again.

the void inside the run is just indicating that their are no parameters to pass to the function(as epicpunnum said), so you can freely think of run() and run(void) as the same thing.

in short, don't break the loop inside run, just do a conditional check inside the loop that if(isRunning==true), and put your logic inside that.

alternatively, you coud do:

void run(){
while(!isDone){
if(!isRunning) continue; //goes back to the beginning of the loop.
//your code here!
}
};


basically, your core problem is that you call run() inside your input code, instead you need to re-think how you manage your main loop with pause/unpause.

what do you mean by input logic? on a side note, isn't a game loop consider to be an infinite loop if runs constantly to do handling tasks like drawing objects and testing collisions?

### #1warnexus

Posted 09 February 2013 - 11:04 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?)

because my approach was to pause the game. The only way to do it is to break out of the gameLoop. If I unpause the game, I need to call the run method which execute the game loop to keep things drawing again. the run method needs to be called by the programmer. the key events are in the keyPressed method of the Game class since the Game class will be responsible for controlling the pause/unpause nature of the game.

Are you sure you saw my code?

think about what it means to start an infinite loop inside your input logic thread.  and as far as i can see, that infinite loop does not check your input.

so yes, we need to see more code(unless my above assumption is correct, and that is why you can only pause/unpause once)

insead of doing:

void run(void){
while(isRunning){
}
}


try:

void run(void){
while(!isDone){
if(isRunning){
//game logic here
}
}


why is void a parameter and is not given a data type? I posted my game loop below since I cannot longer edit my initial post.

public void run(){
// basic game loop
while(isRunning){
// calculate the time since the last loop
long milliseconds = System.currentTimeMillis() - lastTick;
lastTick = System.currentTimeMillis();

// set the focus to the panel
panel.requestFocus();

// get graphics context
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
clearBuffer(g);

// update all game items
for(GameComponent component : gameObjects){
component.update(milliseconds);

}

// handle the dynamic objects
addNewGameComponents();
removeOldGameComponents();

// draw all game items
for(GameComponent component: gameObjects){
component.draw(g);
}

/* do a bounding box collision of the laser with the
*  oneEye monster's bounding box every game loop
*  which is basically every time the game redraws
*  itself.
*  Collision test applies to ALL laser being drawn on screen!
*
*  The easiest way is to check every instance of type Laser in the
*  ArrayList and tell them to do monster collision detection
*/

// laser check for every OneEye monsters in the ArrayList
for(GameComponent component: gameObjects){
if(component instanceof Laser)
{
((Laser) component).checkMonsterCollision(gameObjects);

}
if(component instanceof OneEyeSlashSkill)
{
((OneEyeSlashSkill) component).checkShipCollision(gameObjects);

}

}

flipBuffer(g);

// pause for a bit so we don't consume 100% CPU

try { Thread.sleep(10); } catch (Exception e) {}

}
}

ok, so i'm fairly certain(note: i've used little java, so i might be wrong in how java handle's things) the problem is as i described, you are calling run inside your input logic, this means that you essentially never get back to check input again.

the void inside the run is just indicating that their are no parameters to pass to the function(as epicpunnum said), so you can freely think of run() and run(void) as the same thing.

in short, don't break the loop inside run, just do a conditional check inside the loop that if(isRunning==true), and put your logic inside that.

alternatively, you coud do:

void run(){
while(!isDone){
if(!isRunning) continue; //goes back to the beginning of the loop.
//your code here!
}
};


basically, your core problem is that you call run() inside your input code, instead you need to re-think how you manage your main loop with pause/unpause.

what do you mean by input logic?

PARTNERS