[3730] in java-interest
Odd timing on Turkey Day
daemon@ATHENA.MIT.EDU (ian c rogers)
Fri Nov 24 01:33:14 1995
From: "ian c rogers" <irogers@ghostfacekiller.biggun.com>
Date: Thu, 23 Nov 1995 17:24:53 -0800
Reply-To: irogers@biggun.com
To: java-interest@java.sun.com
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.
Also, the time it takes to load large PEOPLE image can vary greatly. I tried
making AnimateUFO() synchronized, and all I received was the last frame
of the animation.
I've experienced these timing problems at various places in my apps. I've
found that if I try to animate more than on small image on a large canvas, and
repaint is called too close in succession, the first call to repaint
will seem to be ignored.
Why does the second function run before the first is complete?
Why can it take 3 seconds or 2 minutes for the same image to load?
Has anyone experienced problems calling repaint quickly in succuession to
animate different images?
I'm going to include a piece of the code I just put together. Feel free to
suggest better ways of accomplishing my goal. I take criticism thankfully.
public void run()
{
AnimateUFO();
AnimatePeople();
}
public void AnimateUFO()
{
dbg("about to load the UFO image...");
tellLoadingMsg(ufo, imageLabel);
ufoImage = getImage(ufo);
tracker.addImage(ufoImage,1);
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);
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();
}
/**
* Let's override update to see if we can get rid of that
* nasty flicker.
*/
public synchronized void update(Graphics g)
{
g.clipRect(Math.min(xPos,lastUpperLeft.x),
Math.min(yPos,lastUpperLeft.y),
Math.max(xPos+swidth,lastLowerRight.x),
Math.max(yPos+sheight,lastLowerRight.y));
paint(g);
}
/**
* Paint the current frame.
*/
public void paint (Graphics g)
{
if ( error || !loaded)
{
g.drawImage(backgroundImage, 0, 0, this);
}
else
{
offScrGC.drawImage(backgroundImage, 0, 0, this);
if ( image != null )
{
if ( strip )
{
offScrGC.clipRect(0,321,245,550);
offScrGC.drawImage(image, xPos, yPos, swidth, sheight, this);
}
else
{
offScrGC.drawImage(image, xPos, yPos, swidth, sheight, this);
}
}
g.drawImage(offScrImage, 0, 0, this);
lastUpperLeft.move(xPos, yPos);
lastLowerRight.move(xPos+swidth,yPos+sheight);
}
}
--
ian c rogers http://www.filmzone.com/
Big Gun Project http://www.crashsite.com/Crash/
irogers@biggun.com http://www.nando.net/music/gm/
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com