2012-02-26 145 views
1

SomeClass.cs清除屏幕

public void clearscreen() 
{ 
    main.GraphicsDevice.Clear(Color.Black); 
} 

爲什麼我不能調用從另一類這個方法清屏?

protected override void Draw(GameTime gameTime) 
{ 
    GraphicsDevice.Clear(Color.Black); 
    spriteBatch.Begin(); 
    mainMenu.MenuDraw(); 
    spriteBatch.Draw(cursorTexture, cursorPosition, Color.White); 
    spriteBatch.End(); 
    base.Draw(gameTime); 
} 

從mainMenu.Draw()中調用clearscreen方法;

+0

當你嘗試時會發生什麼? – 2012-02-26 06:39:51

+0

在調用該方法之前,我在屏幕上繪製了一個圖像。調用該方法後,圖像仍在屏幕上。 – KeyHeart 2012-02-26 06:41:08

+0

你確定你在Draw(GameTime gametime)方法中調用這個方法..你能向我們展示你的Draw方法代碼嗎? – 2012-02-26 06:59:05

回答

1

你需要通過你的GraphicsDeviceManager(最有可能命名爲「圖形」)的類並把它作爲如此。

graphics.GraphicsDevice.Clear(Color.Black); 
2

使用此在您的繪製方法:

protected override void Draw(GameTime cGameTime) 
{ 
     GraphicsDevice.SetRenderTarget(null); 
     GraphicsDevice.Clear(Color.Black); 
     .... 
     .... 
     ....