Olá a todos!
bem, estou desenvolvendo um game para a faculdade, mas estou encontrando problemas...
O jogo em si está pronto,e agora fiz um menu inicial para ele mas na hora de integrar, o jogo não funciona.
Inicialmente fiz o menu em um JFrame e o jogo em outro, e quando o usuário apertasse Start Game o Frame do jogo apareceria e o do menu desapareceria. Até aí tudo bem, mas o jogo fica descentralizado no frame novo, e não responde aos comandos do teclado nem nada. Até o X para fechar para de funcionar. Tenho que fechar o programa pelo gerenciador de tarefas....
Então tentei fazer tudo em um frame só e o problema da descentralização diminuiu, mas não foi resolvido, e o jogo continua sem responder...
aqui estão os códigos que criam os frames:
cria a tela com o menuInitial(){
setTitle("Chicken Killer");
setSize(new Dimension(800,600));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
back = SpriteStore.get().getSprite("sprites/front.jpg");
menuShown = false;
addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
if (menuShown){
if (e.getKeyCode() == KeyEvent.VK_UP) {
menu.selectPreviousOption();
paintScreen();
}
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
menu.selectNextOption();
paintScreen();
}
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
enterPressed();
}
}
else {
menu = new Menu();
menuShown = true;
paintScreen();
}
}
public Game(Initial menuScreen) {
menuScreen.dispose();
// create a frame to contain our game
JFrame container = new JFrame("ChickenKiller");
// get hold the content of the frame and set up the resolution of the game
JPanel panel = (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(800,600));
panel.setLayout(null);
// setup canvas size and put it into the content of the frame
setBounds(0,0,800,600);
panel.add(this);
// Tell AWT not to bother repainting our canvas since we're
// going to do that our self in accelerated mode
setIgnoreRepaint(true);
// make the window visible
container.pack();
container.setResizable(false);
container.setVisible(true);
// add a listener to respond to the user closing the window.
container.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// add a key input system (defined below) to canvas
// so it can respond to key pressed
addKeyListener(new KeyInputHandler());
// request the focus so key events come to us
requestFocus();
// create the buffering strategy which will allow AWT
// to manage the accelerated graphics
createBufferStrategy(2);
strategy = getBufferStrategy();
//initializes the game entities
initEntities();
}
Obrigada pela atenção!

