Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] A few applet issues..

Started by dwfait Apr 2, 2009 at 2:26 AM 1 replies 650+ views
Original Post
dwfait
dwfait
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. If anyone's interested, the applet is at: www.someonestudios.com/test Thanks
VildNinja
VildNinja
do you really need 100 fps??

why don't just draw on mouse input, and whenever the AI has taken its turn?

as for your problems with minimized window, be sure to call setIgnoreRepaint(true); although that should be set as default.. can i see your paint() and update() methods?
VildNinja
VildNinja
Here is some basic code for double buffering

buffer is a BufferedImage object
and b is a Graphics object
where b = buffer.getGraphics();

	@Override	public void update(Graphics g)	{		paint(g);	}		@Override	public void paint(Graphics g)	{		// first clear the BufferedImage		b.setColor(Color.BLACK);		b.fillRect(0, 0, 800, 600);				// then draw something with b				// finaly draw the BufferedImage to the JApplet		g.drawImage(buffer, 0, 0, this);	}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.