Skip to main content

Clearing the screen

2 replies [Last post]
hooligancat
Offline
Joined: 2009-10-20
Points: 0

I am using the following code to wipe the screen of any graphics items. In 1 player the graphics remain on screen.

public static Color m_transparent = new Color(0, 0, 0, 0);

Graphics2D g = (Graphics2D) m_component.getGraphics();
if (g != null)
{
g.setComposite(AlphaComposite.Src);
g.setColor(m_transparent);
g.fillRect(x, y, w, h);
Toolkit.getDefaultToolkit().sync();
g.dispose();
}

I was under the impression that Toolkit.getDefaultToolkit().sync() ensures that the screen is upto date with any events. If this is the case is the final event not fillrect (in this case the values would be 0, 0, 1920, 1080), meaning clear?

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hooligancat
Offline
Joined: 2009-10-20
Points: 0

That seems to have done the trick. Thanks.

2themax
Offline
Joined: 2008-01-22
Points: 0

This is instead.

Graphics2D g = (Graphics2D) m_component.getGraphics();
if (g != null)
{
g.setComposite(AlphaComposite.Clear);
g.fillRect(x, y, w, h);
Toolkit.getDefaultToolkit().sync();
g.dispose();
}