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

[java] Back Buffer

Started by NightMonkey Jun 26, 2004 at 4:04 PM 2 replies 1k views
Original Post
NightMonkey
NightMonkey
Im trying to draw several images to a back buffer so I can draw them as one image. Here is the code: Image BackgroundImage, BackBuffer; public void init() { Toolkit toolkit = Toolkit.getDefaultToolkit(); BackgroundImage = toolkit.getImage("images/scene2.jpg"); BackBuffer = createImage(APP_XSIZE,APP_YSIZE); } public void paint(Graphics g) { BackBuffer.getGraphics().drawImage(BackgroundImage,0,0,this); g.drawImage(BackBuffer,0,0,this); } I have tried drawing the image directly to g and it works but i wont work when drawing the image to the BackBuffer first. Does anyone know why this is happening? Thanks in advanced.
nonnus29
nonnus29
That looks ok, I'd say your problem is somewhere else.
aidan_walsh
aidan_walsh
Are you using the same paint() method all the time? Going by the code given here, all the images are going to overlap each other, because they are all being drawn at 0,0. Instead of specifying the co-ordinates, you should instead get the X and Y dimensions of the image, and calculate based on those where the images should go...
www.aidanwalsh(.net)(.info)
Addictman
Addictman
Have you tried disposing the backbuffer?

public void paint(Graphics g)
{
Graphics2D g2 = Backbuffer.getGraphics();
g2.drawImage(..)
g2.dispose();

g.drawImage(...);
}

Development blog, The Omega Sector -- http://www.omegasector.org

Topic Locked

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

Sign in to reply to this topic.