My professor wrote this DrawingPanel.java thing we use to draw images. I created an animation, having it draw several layers, sleep at the end, then draw the next frame, sleep, next frame, etc.
The problem I'm having is that it's drawing each step before sleeping, so I experience some pop-in -- for example, the first step is to draw the green background, the last step is to draw a vehicle, but for a brief millisecond the background will be drawn on top of the truck, so the truck blinks in and out. I want it to draw an entire frame and then display it.
I asked my TA how I could do that, he gave me a bit of guidance -- he said "Essentially, you need to draw everything onto a BufferedImage, then draw the BufferedImage onto the DrawingPanel. That means you’ll need a few Graphics objects. You need one that talks to the DrawingPanel like usual, and you need one that talks to the BufferedImage. You’ll also need to convert these into Graphics2D objects, because only they know how to deal with BufferedImage. You do this with a cast, as in Graphics2D g2 = (Graphics2D)g"
I understand the cast part, but not really the BufferedImage stuff. This is only the third week of my first quarter of programming, so it'd be nice if anyone could translate this to plain English. I can PM my program if that'd help.
The problem I'm having is that it's drawing each step before sleeping, so I experience some pop-in -- for example, the first step is to draw the green background, the last step is to draw a vehicle, but for a brief millisecond the background will be drawn on top of the truck, so the truck blinks in and out. I want it to draw an entire frame and then display it.
I asked my TA how I could do that, he gave me a bit of guidance -- he said "Essentially, you need to draw everything onto a BufferedImage, then draw the BufferedImage onto the DrawingPanel. That means you’ll need a few Graphics objects. You need one that talks to the DrawingPanel like usual, and you need one that talks to the BufferedImage. You’ll also need to convert these into Graphics2D objects, because only they know how to deal with BufferedImage. You do this with a cast, as in Graphics2D g2 = (Graphics2D)g"
I understand the cast part, but not really the BufferedImage stuff. This is only the third week of my first quarter of programming, so it'd be nice if anyone could translate this to plain English. I can PM my program if that'd help.
Last edited by a moderator: