Hi,
I am making a multithreaded pacman game.
There is a PacmanController class which extends JFrame, a Maze class which extends JPanel, a Pacman class which runs in its own thread and extends JPanel, and a Ghost class which runs in its own thread and extends JPanel. Each thread (pacman and each Ghost) continuously repaints itself and calls maze.repaint() as well.
When I add the maze to the frame, it displays fine, if I then add pacman, it still displays and animates fine.
However, when I add the Ghost to the frame after pacman, the ghost appears and pacman disappears. If I switch the order in which pacman and the ghost are added, the opposite is true i.e. only one of pacman or each instance of ghost is ever displayed - the one which is added last.
Eg:
add(maze);
add(pacman);
add(ghostA);
Only the maze and ghostA appear?
I realize this has something to do with JFrames BorderLayout, i.e. only one component can be added to the center region, but don't know how to fix it. I have tried adding pacman and ghosts to EAST WEST etc but this didn't work.
I have also tried
maze.add(pacman);
add(pacman); //etc
but this didn't work either.
Sorry for the long post, any help is much appreciated. I can't post any code as the code is too long and spread over many classes.
Many thanks!