MSDN Library
EN
此内容没有您的语言版本,但有英语版本。

Tinting a Sprite

Demonstrates how to tint a sprite using a Color value.

The Complete Sample

The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

Drawing a Tinted Sprite

To draw a tinted sprite

  1. Follow the procedures of Drawing a Sprite.
  2. In the Update method, determine how to tint the sprite.

    In this example, the value of the game pad thumbsticks determine the Red, Green, Blue, and Alpha values to apply to the sprite.

    protected Color tint;
    protected override void Update(GameTime gameTime)
    {
        ...
        GamePadState input = GamePad.GetState(PlayerIndex.One);
        tint = new Color(GetColor(input.ThumbSticks.Left.X),
            GetColor(input.ThumbSticks.Left.Y),
            GetColor(input.ThumbSticks.Right.X),
            GetColor(input.ThumbSticks.Right.Y));
    
        base.Update(gameTime);
    }
    
  3. In the Draw method, pass the color value created in Update to SpriteBatch.Draw.

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
    
        spriteBatch.Begin();
        spriteBatch.Draw(SpriteTexture, position, tint);
        spriteBatch.End();
    
        base.Draw(gameTime);
    }
    
  4. When all of the sprites have been drawn, call End on your SpriteBatch object.

社区附加资源

添加
显示:
© 2016 Microsoft