私は戻ってきて、ここ数週間は順調に進歩していますが、これは過去 3 日間ほど私を困惑させ、ブレークスルーはありませんでした.
このコードは参照用です。
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();
}
これは、同じ名前を共有する 3 つのメソッドの 1 つです。パラメーターを受け入れず、マップ全体 (レイヤーとすべて) を更新するメソッドがあり、このコードは機能します。
しかし、ユーザーが (タイルの配置/削除によって) マップを更新するとき、マップ全体を再描画したくありません。代わりに、変更が加えられた特定のスペースを更新したいだけです。各レイヤーを更新する(そこに描かれたタイルを切り替えることによって)などの代わりに、古いタイルの上に新しいタイルを配置するだけでした。変更をペイントする前にそれをペイントすると問題が修正されると考えて、blankTile ビットマップを追加しましたが、そうではありません。
私の質問は次のとおりです。ビットマップ上の特定のタイルを更新して、そこにあるものを削除して新しい画像に置き換える方法はありますか?
必要に応じて、さらに情報を提供できます。組み込みの GDI ライブラリを引き続き使用したいのですが、この問題を解決する唯一の方法が切り替えることである場合は、そうします。しかし、グラフィック ライブラリを切り替えることなく、この特定の問題を解決する方法があるはずです。これまでのところ、このプロジェクトのニーズを十分に満たしています (この特定のエラーを除く)。