2
有趣的問題!基本上我有一個計時器,用於我的用戶界面,從99開始倒數。一切正常,除了在舊時間之外繪製新時間的事實。 (前一次沒有清除)在GameplayScreens繪圖調用中發生了一個明顯的事情,儘管......它很奇怪。定時器自己繪製,不清除
這裏是我的相關功能:
GameplayScreen.cs(或我們平常的Game1)
public override void Update(GameTime gameTime)
{
m_GameUI.Update(gameTime);
m_GameCam.lookAt(m_Hero.Position);//feeds the camera's lookAt function the players vector2 position
m_GameUI.lookAt(m_GameCam.Position); //Look at the camera's position :D
}
public override void Draw(GameTime gameTime)
{
ScreenManager.GraphicsDevice.Clear(ClearOptions.Target,
Color.CornflowerBlue, 0, 0);
SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
m_BackgroundManager.Draw(spriteBatch, m_GameCam);
//Begin the Spritebatch Drawing
spriteBatch.Begin(SpriteSortMode.Immediate, null,
null,
null,
null,
null, m_GameCam.ViewMatrix);
//Call EntityManager.DrawAllEntities()
EntityManager.Instance.DrawAllEntities(gameTime, spriteBatch);
//End the spritebatch drawing
spriteBatch.End();
spriteBatch.Begin();
m_GameUI.Draw(gameTime, spriteBatch);
m_PlayerUI.Draw(gameTime, spriteBatch);
spriteBatch.End();
}
GameUI.cs
SpriteFont m_Font;
double m_Timer;
public virtual void Update(GameTime gameTime)
{
m_Timer -= gameTime.ElapsedGameTime.TotalSeconds;
}
public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
spriteBatch.Draw(UITexture, Position, Color.White);
spriteBatch.DrawString(m_Font, "" + (int)m_Timer + "", new Vector2(380, 45), Color.White);
}
有沒有你不使用'GraphicsDevice.Clear(彩色)'理由嗎?另外,ScreenManager是什麼? – neeKo
我的遊戲有不同的菜單狀態,由ScreenManager控制,其中GraphicsDevice被定義,其中一個是* GameplayScreen *,其中游戲邏輯實際踢入。我在頂部的GameplayScreen繪圖中執行我的清除「ScreenManager.GraphicsDevice.Clear (ClearOptions.Target, Color.CornflowerBlue,0,0);「 – EmericanFlow
如果您只使用Clear(Color.CornflowerBlue),它會有所作爲嗎?我從來沒有見過使用重載,除非你的參數被用於某種原因(它們看起來像默認值),使用單一顏色參數重載更簡單。 –