简体   繁体   English

如何在XNA中更改背景颜色

[英]How do I change the background color in xna

This code is in the update method, and I think that just means that this is what happens when the screen updates, but I'm not sure.I am wonder specifically about the lines of code 6-10. 这段代码在update方法中,我认为这只是意味着屏幕更新时会发生这种情况,但我不确定。我特别想知道代码6-10的行。 I am trying to make it so when the mouse is on the screen the screen turn green. 我正在尝试这样做,因此当鼠标在屏幕上时,屏幕变成绿色。

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

You must change the Draw method to use the variable when clearing the screen. 清除屏幕时,必须更改Draw方法以使用该变量。

Make sure the backcolor variable is declared as a class level variable of type Microsoft.XNA.Framework.Color 确保将backcolor变量声明为Microsoft.XNA.Framework.Color类型的类级别变量。

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

    // Add Draw code here

    base.Draw(gameTime);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM