XNA에서 "떨어지는 모래"게임을하고 있습니다. 물론, 많은 픽셀이 필요합니다. 그것은 순수하게 알고리즘을 테스트하기 위해 픽셀 당 투명한 파란색을 사용하여 시작되었습니다. 프레임 속도 (일정한 60 FPS)를 잃기 전에 약 10 만 픽셀을 화면에 표시 할 수있었습니다. 이는 필요한 것보다 많았습니다! 그러나 마침내 다른 색상의 픽셀 (파란색과 빨간색)을 추가하고 다른 변경 사항을 추가하지 않은 경우 FPS가 기하 급수적으로 떨어지고 FPS가 약 10으로 떨어지기 전에 약 10,000 픽셀 만 화면에 표시됩니다. 일부 실험을 마친 후, 스프라이트 배치가 잘못되었을 가능성이 가장 높았습니다. 스프라이트 배치가 자동으로 픽셀을 정렬하고 블렌드하기 때문에 완전히 틀릴 수도 있지만 다른 것을 생각하면 알려주십시오. 나는 두 색을 혼합하는 행위가 속도를 잃어 가고있는 것으로 생각한다. 그렇다면 어떻게 스프라이트 배치의 메소드를 사용할 수 있습니까? 아니면 완전히 기지에서 벗어나나요?SpriteBatch 정렬을 우회하는 방법? C# XNA
나는 SpriteSortMode 및 BlendMode를 사용하여 엉망으로 만들었으며 심지어 스프라이트 배치 호출 당 컬러 픽셀과 같은 그리기를 시도했지만 지금까지는 행운이 없습니다.
또한 화면에 그리는 픽셀의 좌표가 처음부터 같아서 블렌딩 등이 필요하지 않습니다. 내가 추가 색상을 추가 할 때까지 (약 60fps의 그려 100,000 픽셀)를 다시
//Game Draw Method
protected override void Draw(GameTime gameTime)
{
stopWatch.Start();
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
//backgroundSprite.Draw(spriteBatch);
terrainSprite.Draw(spriteBatch);
resourceMap.Draw(spriteBatch, spriteFont);
frameCounter++;
string fps = string.Format("fps: {0}", frameRate);
int totalint = 0;
for (int i = 0; i < resourceMap.activeCoordinates.Count; i++)
{
totalint += resourceMap.activeCoordinates[i].Count;
}
string total = string.Format("resource count: {0}", totalint);
spriteBatch.DrawString(spriteFont, fps, new Vector2(33, 33), Color.White);
spriteBatch.DrawString(spriteFont, total, new Vector2(33, 45), Color.White);
spriteBatch.DrawString(spriteFont, totalTime, new Vector2(33, 17), Color.White);
spriteBatch.DrawString(spriteFont, totalTime, new Vector2(33, 17), Color.White);
spriteBatch.End();
stopWatch.Stop();
totalTime = "Draw Time: " + stopWatch.Elapsed;
stopWatch = new Stopwatch();
base.Draw(gameTime);
}
//resourceMap.Draw(SpriteBatch spriteBatch, SpriteFont font) from Game Draw
public void Draw(SpriteBatch spriteBatch, SpriteFont font)
{
//spriteBatch.End();
//this was originally one for loop to draw all pixels, but was separated to draw each different color pixel after discovering performance issue
for (int c = 0; c < activeCoordinates.Count(); c++)
{
//spriteBatch.Begin();
for (int i = 0; i < activeCoordinates[c].Count; i++)
{
mapArray[(int)activeCoordinates[c][i].X][(int)activeCoordinates[c][i].Y].Draw(spriteBatch);
}
//spriteBatch.End();
}
//spriteBatch.Begin();
spriteBatch.DrawString(font, timeInMilli, new Vector2(33, 0), Color.White);
}
는, 코드에 만든 유일한 변화가 그려 질 픽셀의 목록에 다른 색상을 추가, 그래서 여기 코드는 좋은 일하고 있었다 .
도움 주셔서 감사합니다.
코드는 draw 메서드가있는 for 루프만큼 간단합니다. 설명만큼이나 도움이되어서는 안되지만 거기에 가면 ^^. – Colton
'mapArray [] []. Draw '가 무엇이든간에 코드를 추가 할 수 있습니까? 각 픽셀을 개별 스프라이트로 그리는 것이 어쨌든이 잘못된 해결책 일 가능성이 높습니다. –
나는 모든 모래 입자에 대해 하나의 텍스처이지만 다른 색상으로 착색 된 흰색 픽셀을 그려서 문제를 해결할 수 있다고 생각합니다. 문제가 게시하지 않은 다른 항목에도있을 수 있지만 프레임 속도가 올라갈 수 있습니다. 하지만 그렇습니다. 각 모래 입자에 대해 하나의 픽셀 텍스처를 그리는 것은 대단히 느린 접근법입니다. 인터넷 검색 * 가루 * 게임을 시도하고 그들이 그것을 어떻게. – user1306322