Link to home
Start Free TrialLog in
Avatar of DGeomel
DGeomelFlag for Germany

asked on

JDK 1.02 - drawImage(x, y, w, h, observer) behaviour

I'm writing a game in Java, for which I create two threads,
one for event and game handling, and one for redrawing and
updating the screen (in the usual way, using an off-screen
GC, etc.). Most of the time I use the drawImage(x, y, obsr)
function for drawing the sprites, because their width and
height is constant. But I wanted to create a dynamic scaling
effect for some of them, so I decided to create a loop where
the width and height (not of the actual image, but that
which I wish to draw on screen) change from 0 to some fixed
numbers and use drawImage(x, y, width, height, obsr) to
draw the scaled image on screen.
The problem is that, while with the 1st drawImage() I get
no flashing and tearing (I already mentioned I'm using an
off-screen GC and a media tracker to eliminate these), with
the scaling version I get significant flashing and tearing
all over the window of the applet and I never get to see the
drawn image!
So, what's going on? Any workarounds?(besides using JDK 1.1)

Thanks in advance
Avatar of jpk041897
jpk041897

Have you looked into double buffering?
ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You say you are using "an offscreen GC..." - can you explain what you mean?  I generally take "offscreen" to imply a double buffering approach, but GC usually means "garbage collection."

The difference in your approaches is that the scaling takes noticeably more time, so double buffering is essential.
Avatar of DGeomel

ASKER

To russgold: By "GC" I mean "Graphics Context". I think the term
is not used in Java, but if you've programmed in other platforms
(e.g. Windows) you must've stumbled upon it before.

To jpk: By using an off-screen GC I AM using double-buffering.

To imladris: Thanks, it solved my problem too, but I need some
more clarification:
I want to scale one image for which I use getImage();
If I have to create 10 scaled versions of the same image, I
will call getImage() 10 times with the same filename, and
call the scaled version mediatracker:addImage() for each of them.
But does the file get downloaded 10 times, or only once (and then
processed locally to create the scaled versions)?