I'm back, and I've been making smooth progress over the last few weeks but this has stumped me for the last three days or so with no breakthroughs.
This code is for reference.
private void paintMap(int xToUpdate, int yToUpdate, int layerToUpdate)
{
// this should ONLY be called if mapBitmap has already been drawn initially
Graphics gfx;
// create a blank tile to place on top of whatever tile they want to place (to sucessfully update our tile)
Bitmap blankTile = new Bitmap(Program.pixelSize, Program.pixelSize);
gfx = Graphics.FromImage(blankTile);
gfx.Clear(Color.Transparent);
gfx = Graphics.FromImage(mapBitmap[layerToUpdate]);
// only draw a map, if a map has been loaded
if (mapLoaded)
{
#region Draw Map Loop
// draw the map
// find the tile at that point
int tile = map.mapTile[xToUpdate][yToUpdate].getTileLayer(layerToUpdate);
int x1 = Program.getTileXLocation(tile);
int y1 = Program.getTileYLocation(tile);
// set the tile's rectangle location
srcRect = new Rectangle(x1 * Program.pixelSize, y1 * Program.pixelSize, Program.pixelSize, Program.pixelSize);
// draw the tile
gfx.DrawImage(blankTile, xToUpdate * Program.pixelSize, yToUpdate * Program.pixelSize);
gfx.DrawImage(gfxTiles, xToUpdate * Program.pixelSize, yToUpdate * Program.pixelSize, srcRect, units);
// weather crap
// screenMain.DrawImage(gfxNight, x1 * Program.pixelSize, y1 * Program.pixelSize, night, units);
#endregion
}
else // otherwise, a map hasn't been loaded; clear the drawing surface
{
gfx.Clear(Color.Black);
}
gfx.Dispose();
}
This is one of three methods that share the same name. I have a method that accepts no parameters, and refreshes the entire map (layers and all) and this code works.
But, when a user updates a map (by placing/removing a tile), I don't want to repaint the entire map. instead, I want to just update that particular space with the changes being made. Instead of updating each layer (by switching the tile painted there), etc etc, all the method did was place new tiles on top of the old ones. I added the blankTile bitmap, thinking that painting that, before painting the changes would rectify the issue, but it doesn't.
My inquiry is this: is there any way to just update that particular tile on the bitmap by deleting what is there and replacing it with the new image?
I can give more information if needed. I would like to keep using the built in GDI libraries, but if the only way to fix this problem is to switch, I would do so. But I'm almost sure there should be a way to fix this particular issue without switching my graphics library out. So far, it more than suits the needs of this project (minus this particular error).