如何更改xna中的背景颜色

时间:2017-03-12 07:32:28

标签: c# xna

此代码在更新方法中,我认为这只是意味着屏幕更新时会发生这种情况,但我不确定。我特别想知道代码行6-10。我试图这样做,当鼠标在屏幕上时,屏幕变绿。

protected override void Update(GameTime gameTime)
{

    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        this.Exit();
    MouseState current_mouse = Mouse.GetState();
    int mousep1 = current_mouse.X;
    int mousep2 = current_mouse.Y;
    if (current_mouse.X >= 0)
    {
        backcolor = Color.Green;
    }
    base.Update(gameTime);
}

1 个答案:

答案 0 :(得分:0)

在清除屏幕时,必须更改Draw方法以使用该变量。

确保将backcolor变量声明为类型Microsoft.XNA.Framework.Color的类级变量

protected override void Draw(GameTime gameTime)
{           
    GraphicsDevice.Clear(backcolor);

    // Add Draw code here

    base.Draw(gameTime);
}
相关问题