私のタイルを描画するこのメソッドは非常に遅いようですが、私は正確に何が間違っているのかわからない、私のカリングメソッドがうまく動作せず、オフスクリーンのものを描画しています。ここでは、次のとおりです。XNA - カリングパフォーマンスの問題
// Calculate the visible range of tiles.
int left = (int)Math.Floor(cameraPosition.X/16);
int right = left + spriteBatch.GraphicsDevice.Viewport.Width/16;
right = Math.Min(right, Width) + 1; // Width -1 originally - didn't look good as tiles drawn on screen
if (right > tiles.GetUpperBound(0))
right = tiles.GetUpperBound(0) + 1; // adding 1 to get the last right tile drawn
int top = (int)Math.Floor(cameraPosition.Y/16);
int bottom = left + spriteBatch.GraphicsDevice.Viewport.Height/ 16;
bottom = Math.Min(bottom, Height) + 1; // Height -1 originally - didn't look good as tiles drawn on screen
if (bottom > tiles.GetUpperBound(1))
bottom = tiles.GetUpperBound(1) + 1; // adding 1 to get the last bottom tile drawn
// For each tile position
for (int y = top; y < bottom; ++y)
{
for (int x = left; x < right; ++x)
{
// If there is a visible tile in that position, draw it
if (tiles[x, y].BlockType.Name != "Blank")
{
Texture2D texture = tileContent["DirtBlock_" + getTileSetType(tiles,x,y)];
spriteBatch.Draw(texture, new Vector2(x * 16, y * 16), Color.White);
if (isMinimap)
spriteBatch.Draw(pixel, new Vector2(30+x, 30+y), Color.White);
}
}
}
GetTileSetTypes
などDirtBlock_North、DirtBlock_Center、同様に、異なるテクスチャのために、その周りにあるものをタイルを取得するための機能であるタイルコンテンツが私のブロックのテクスチャを持つだけのクラスです。
どのようにこれが遅いコードであると判断しましたか?フレームあたりのタイル数はどれくらいですか?どこでSpriteBatch.Beginと.Endを呼び出しますか? –
それは間違いなくSpriteBatchの問題ですが、タイルの図面をスキップするだけですが、ロードの衝突などでは30fpsが得られます。これは、私が、上のカリング方法がまだスクリーンから外れていると思って、グラフィックを切り替えることが問題であると考えさせる。 – Cyral
おそらくプロファイラを使用して、何が遅くなっているのかを正確に突き止めることができます。例:SlimTune; http://code.google.com/p/slimtune/ –