내 타일을 그리는이 방법은 아주 느린 것 같습니다. 정확히 무엇이 잘못 되었습니까, 내 도형 방법이 작동하지 않고, 화면이 보이지 않는 물건을 그리는 것 같지만, 확실하지는 않습니다. 여기있다 :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를 얻습니다. 이것은 상단의 컬링 (culling) 방법이 여전히 화면에서 물건을 그리는 것으로 생각하고, 그래픽을 전환하는 것이 문제라고 생각하게합니다. – Cyral
아마도 프로파일 러를 사용하여 느리게 진행되는 원인을 정확히 찾아 낼 수 있어야합니다. 예 : SlimTune; http://code.google.com/p/slimtune/ –