Translucent images & screen refreshing

Jdo300

New member
Joined
Dec 6, 2003
Messages
4
Location
Ohio
Hi, I have two questions. Both concern this board game type program that Im working on.

1. The game uses pawns to represent the players and they are supposed to look glassy when they are drawn on the board. I want to make them appear semi-transparent against the background of the form. The board itself is made up of a number of tiles that I dynamically draw onto the back of a picture box. All of my graphics for the tiles and the players are stored in image lists. The player images are transparent Gifs and the other tiles are plain bitmaps. What drawing operation should I use to draw the player images onto the background translucently?

2. This concerns refreshing the board. I basically have a loop that controls the movement of the game pieces and every time a player piece moves, the game board is redrawn over again. The problem Im having is that every time I refresh the background (gfxObject.Clear(Color.Transparent)), it flickers a lot and leaves this nasty black background before the tiles are redrawn again. The PictureBox is set to have a background image in it so that
 
Flicker/Alpha

Use the double buffered style of the control class to get rid of flicker. There are lots of posts regarding that elsewhere in here.

If your images really are transparent ( i.e. they have a valid alpha channel ) then setting the graphics property goes something like )

Graphics.CompositingMode = CompositingMode.SourceOver should ensure they appear correctly.

I think this is the default though ...

try testing your images to ensure they really have an alpha channel i.e.
Image.IsAlphaPixelFormat( your image.PixelFormat )

-Duncan
 
Ahhh! Thank you for your reply, I still to this point have not found a good way to display translucent images. What I ended up doinf was taking the pictures I wanted to use, creating graphics objects from them, then maually, I would loop through the alhpa channels of each pixel and set the value to what I want. The method works, but I know its incredibly slow so when I get some time, I will definately try out the method you suggested. Thanks a lot for your input :)
 
Translucent

I have written some apps that overlay several translucent images using ImageAttributes objects to further modify the output pixels. Its works fine and is actually quiet fast until the images get really large.

The main problem is getting the alpha channel correct in the first place. Most paint programs out there do a bad job of saving/modifying alpha channel images. The most reliable and most expensive is Photoshop. Save as a flat PNG and life will be fine.

-Duncan
 
Back
Top