Best way to draw to screen & call game update method?
Hi, I'm currently porting a simple 2D game from C++ to Java, and for the most part I'm done.
Currently, for drawing the stuff to the JApplet, I'm drawing to an offscreen image, and then copying over the image by overriding the paint() method.
Also, to invoke the game update function (the game loop), I have a utility timer running every 10 msecs. This update function also calls the applets repaint() method when it's done.
The problems I'm having, is that the CPU usage of the applet is quite high - about 70%.
I used to be just drawing straight to the applet's Graphics from "getGraphics()", as hte nature of the game means not much changes each "update", so it's innefficient to keep drawing what doesn't change, however, whenever the window was minimized and then brought back up - what was drawn to the screen dissapeared. A solution to this would be ideal.
Also - one more problem. I'm handling the input of game through the applet by registering it as a mouselistener, however, sometimes clicks don't show up (i.e. the mouseClicked() method does not get invoked). Any insight to this problem would be helpful aswell.