# FillRecatangle set Opacity?

I have a game with a HUD which is drawn by fillrectangle.

How would I fade these rectangles when the player is on the HUD?

• What do you mean by fade? Do you want the objects to retain a specific opacity? Or do you want the fillrectangle to visually fade out in a specified amount of time? – jgallant Jul 20 '16 at 17:56
• Stack overflow question with answer: stackoverflow.com/questions/8110975/… – Quintin Steiner Jul 20 '16 at 18:03

## 1 Answer

You can start a new thread, create a loop inside, and invoke this every few ms:

// decalre a golbal int i
i = (i + 1) % 0xFF
Color color = new Color(i, [your color], [your color], [your color]);
g.setColor(myColour); // graphics context object


And you'll see your canvas fading.