用百分比绘制加载屏幕,加载时意味着绘制很多东西

时间:2014-05-20 13:40:57

标签: c# multithreading xna

在我的XNA游戏中,我需要在开始时加载一些图像然后绘制大量图像以供稍后在游戏中使用。我想绘制一个显示进度的装载程序,但是我遇到了一个问题,即在另一个spritebatch已经绘制时我无法绘制。

类似于:

我把它作为一个主题:

public void DrawCache
{
   progress = 0; // I can get this variable from outside
   foreach (SpriteToBeCached in AllSprites)
   {
      graphicsDevice.SetRenderTarget(SpriteToBeCached.MyCachedTexture);
      spriteBatch.Begin();
      spriteBatch.Draw( ... );
      spriteBatch.End();
      graphicsDevice.SetRenderTarget(null);
      ++progress;
   }
}

更新菜单状态:

   ...
   if (!loading)
   { 
       var loading_thread = new Thread(DrawCache);
       loading = false;
   }
   ...

绘图菜单状态:

   ...
   GraphicsDevice.Clear(Color.Black);
   spriteBatch.Begin();
   spriteBatch.DrawString(font, progress, position, Color.White);
   spriteBatch.End();
   ...

我该如何解决这个问题?

0 个答案:

没有答案