Search code examples
c#xna

Clearing the screen


SomeClass.cs

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

Why can't I clear the screen by calling on this method from another class?

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);
}

The clearscreen method is being called from within mainMenu.Draw();


Solution

  • You need to pass your GraphicsDeviceManager (most likely named 'graphics') to the class and call it as so.

    graphics.GraphicsDevice.Clear(Color.Black);