I have game that uses a background image map. On the map I draw game pieces, and when the user clicks on an area I draw a highlight on the section they clicked. So I've created 4 global images, one for each plus one to pass to the drawing section. The final result is that all 4 images look the same. It must be something to do with passing by reference - are they all the same image? I would expect variables of different names to remain independent. When I use clone or new it works correctly but the program runs out of memory after 20 clicks. If I dispose of an image, they all go blank. It would be nice to find a way to make these images pass by value and not reference. They are all the same size, flattened overlays of the original. But I need to preserve the Original and the original + the game pieces, the final highlighted overlay is expendable. Any suggestions on the right approach for this?
Draw d = new Draw();
PassMap = GameMap;
d.DrawMap(UiP, MapHexes, PassMap, Globals.Gaul, Globals.Germania, out DrawnMap);
map.BackgroundImage = DrawnMap;
map.BackgroundImageLayout = ImageLayout.Stretch;
map.Refresh();
PassMap = DrawnMap;
mt.selectHex(Globals.CurrentHex, zoom, MapHexes, HexHighlight, PassMap, out HighlightMap);
map.BackgroundImage = HighlightMap;
map.BackgroundImageLayout = ImageLayout.Stretch;
map.Refresh();
public void selectHex(int hex_id, int zoom, List MapHexes, Bitmap HexHighlight, Bitmap PassMap, out Bitmap HighlightMap)
{
using (Graphics g = Graphics.FromImage(PassMap))
g.DrawImage(HexHighlight, new Rectangle(MapHexes[hex_id].Hex_x - 48, MapHexes[hex_id].Hex_y - 55, HexHighlight.Width, HexHighlight.Height));
HighlightMap = PassMap;
}
When I click around the map, I get a string of highlighted areas, when I only want one. Apparently the HighlightMap is the other maps by reference. If I use new or clone, I get the expected result, but run out of memory after 20 clicks.
Not sure this helps much.