Added called to requestFocus() in GameApplet.init() and GameThread.run()
refs #11 The brute force method of requesting focus seems to be the only fix/workaround that I could find. However it doesn't seem to cause any preformance issues Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -213,6 +213,12 @@ public class AsteroidGameThread extends Thread {
|
||||
while (true){
|
||||
if(isStarted) {
|
||||
|
||||
/*
|
||||
* brute force focus,
|
||||
* this seems to be the only fix I can find, for now
|
||||
*/
|
||||
mGameApplet.requestFocus();
|
||||
|
||||
/*
|
||||
* increment time
|
||||
*/
|
||||
|
||||
@@ -216,6 +216,9 @@ public class GameApplet extends JApplet implements ActionListener, KeyListener {
|
||||
repaint();
|
||||
|
||||
mGameThread.newGame();
|
||||
|
||||
this.setFocusable(true);
|
||||
this.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,6 +257,20 @@ public class GameApplet extends JApplet implements ActionListener, KeyListener {
|
||||
|
||||
@Override
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
switch(e.getKeyCode()){
|
||||
/*
|
||||
* [Enter]
|
||||
* Start of pause the game
|
||||
*/
|
||||
case KeyEvent.VK_ENTER:
|
||||
if(mGameThread.isStarted)
|
||||
mGameThread.pauseGame();
|
||||
else
|
||||
mGameThread.startGame();
|
||||
break;
|
||||
}
|
||||
|
||||
driveShip(e, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user