• Create Account

### #Actualwarnexus

Posted 09 February 2013 - 10:30 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)

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
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) {}

}
}

### #3warnexus

Posted 09 February 2013 - 10:18 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)

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


try:

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


why is void a parameter? here is my game loop since I cannot longer edit my 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
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) {}

}
}

### #2warnexus

Posted 09 February 2013 - 10:18 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)

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


try:

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


why is void a parameter? here is my game loop;

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
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) {}

}
}

### #1warnexus

Posted 09 February 2013 - 10:16 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)

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


try:

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


why is void a parameter?

PARTNERS