Re: "fading" graphics usi
To: comp.lang.java.gui
visionset wrote:
"Brandon McCombs" <none@none.com> wrote in message
news:46552116$0$4719$4c368faf@roadrunner.com...
Hello everyone,
I started a small Java program just as something fun to do. It simulates a
sonar, like on a submarine. Right now I'm at the point where I have
multiple objects moving independently around the sonar screen with a
rotating needle. I keep track of the speed/location/etc. of each object
which extends Thread. The needle rotates around the screen in a way that
lights up the part it just touched and the glow gradually fades away using
a gradient that I created. The objects on the screen only change location
when the needle intersects them (using the intersects() method of
java.awt.geom.Line2D.Double).
...
I think you are on the right track with the transparency overlay.
I would paint a rectangle of eg new Color(1.0,1.0,1.0,alpha) over the icon.
also use a Swing Timer that starts when the icon is first created (needle
pass over).
Actually I already have a Timer that runs the entire time the program
runs. It fires every 6 ms and does all the repainting by calling
repaint() in actionPerformed(). Shortly after posting this I ended up
fixing the problem in the code where the object wasn't disappearing when
it moved out of range and I inadvertently laid the groundwork for fixing
the fading of the objects. I had the revelation for fixing the fading
while laying in bed later that night and tried it first thing Friday
morning and got it working.
I had setup multiple "if" conditions for drawing or not drawing the
objects. As my last condition, which is encountered when the object is
in range but isn't being intersected by the needle, I ended up
creating/calling a variation of each object's display() method which
draws the object with increasing transparency, in effect making it fade
away. With each object tracking its own transparency I was able to make
them all fade properly based on their distance from the needle. The
first condition, when the object is both in range and intersected by the
needle, calls the primary variation of the object's display() method
which will redraw the object and its label with 0 transparency thus
making it appear again (as I timed the fading of each object so that the
object totally disappears right before the needle rotates back around to
intersect it again).
Then every actionPerformed will increase decrease the alpha.
You are going to need to repaint regularly perhaps by another timer purely
for repainting.
See above. I already had that in place. I have 1 timer that repaints
everything in varying layers. The moving vehicles that are tracked on
the sonar are in the top-most layer.
If your app does other intensive stuff you will likely need to make some
drawing optimisations
such as calling repaint(x,y,w,h) to only repaint the areas necessary, eg
icons with attendent rectangles that are not fully opaque. You would union
together the rectangles to obtain the reapaint area.
Since I'm increasingly using more transparencies I'm going to have to
think of ways to optimize it because it is using more and more CPU to
run the program (mainly to repaint I believe). I'll look into your idea
to see if I can get repainting only certain areas to work.
Cache everything that is going to be painted.
Just some ideas,
HTH,
thanks for your help Mike.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24