[3741] in java-interest
Re: Odd timing on Turkey Day
daemon@ATHENA.MIT.EDU (Jim.Graham@Eng.Sun.COM)
Fri Nov 24 22:43:31 1995
Date: Fri, 24 Nov 1995 16:54:59 -0800
To: java-interest@java.Eng.Sun.COM, irogers@biggun.com
From: Jim.Graham@Eng.Sun.COM
Hi Ian,
> I'm trying to animate a couple of small images on a large canvas.
> My run is calling two functions (see below). It appears that the second
> function is called before the first completes. The last UFO image
> (sometimes) is not displayed until the PEOPLE image is loaded.
The problem is that constructing one particular scaled size of an image
does not necessarily mean that you can then render the image at other
scales and get immediate results. Each scaled size of an image is
separately constructed and cached. Moreover, unless you construct them
in parallel, if you construct one size, and then try to draw another
size, we may have to refetch the original image since the raw pixels
may have been decached by the garbage collector in the meantime. Here
is how to modify your example - add the following lines:
> public void AnimateUFO()
> {
> dbg("about to load the UFO image...");
> tellLoadingMsg(ufo, imageLabel);
> ufoImage = getImage(ufo);
> tracker.addImage(ufoImage,1); // May not be necessary?
tracker.addImage(ufoImage,1,125,58); // Track a 125x58 scaled version
tracker.addImage(ufoImage,1,152,77); // Track a 152x77 scaled version
tracker.addImage(ufoImage,1,186,84); // Track a 186x84 scaled version
tracker.addImage(ufoImage,1,222,97); // Track a 222x97 scaled version
tracker.addImage(ufoImage,1,264,120); // Track a 264x120 scaled version
> try {
> tracker.waitForID(1);
> } catch (InterruptedException e) {
> return;
> }
> dbg("done loading the UFO image...");
> clearLoadingMessage();
>
> scaledRepaint( ufoImage, 341, 86, 125, 58);
> nap(500);
> scaledRepaint( ufoImage, 292, 130, 152, 77);
> nap(500);
> scaledRepaint( ufoImage, 242, 162, 186, 84);
> nap(500);
> scaledRepaint( ufoImage, 182, 186, 222, 97);
> nap(500);
> scaledRepaint( ufoImage, 108, 162, 264, 120);
> }
>
> /**
> * AnimatePeople. Time to animate the frightened humans.
> */
> public void AnimatePeople()
> {
> tellLoadingMsg(peopleStrip, imageLabel);
> peopleImage = getImage(peopleStrip);
> tracker.addImage(peopleImage,2); // May not be necessary?
tracker.addImage(peopleImage,2,4400,225); // Track a 4400x225 scale v.
> try {
> tracker.waitForID(2);
> } catch (InterruptedException e) {
> return;
> }
> clearLoadingMessage();
>
> scaledRepaint( peopleImage, 0, 337, 4400, 225);
> }
>
> /**
> * Scaled paint. A little helper to draw a scaled image
> */
> public void scaledRepaint(Image simage, int sxPos, int syPos, int sw, int sh)
> {
> image = simage;
>
> xPos = sxPos;
> yPos = syPos;
> swidth = sw;
> sheight = sh;
>
> repaint();
> }
Note that this repaint does not necessarily get executed immediately.
The repaint method is called "as soon as possible", which means that it
is scheduled to have its update method called at some time in the
future with as little delay as possible. In fact, all of your
"scaledRepaint" calls but the last one may end up ignored as they are
all collapsed into one repaint which is performed with your variables
set up as per the most recent call to this method.
...jim
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com