如何给精灵着色

示范用Color值如何给精灵着色。源代码下载

程序截图

在屏幕上绘制有色彩的精灵

在屏幕上绘制有色彩的精灵

  1. 按照 如何绘制精灵 所讲的1-4步进行操作。

  2. Update方法中,确定如何给精灵着色。

    在本实例中,我们获取游戏机手柄控制杆的值,然后决定应用给精灵的R,G,B和Alpha的值。

    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. 在Draw方法中,将Update中创建的颜色值传递给 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. 绘制完所有的精灵后, 调用SpriteBatch对象的End方法。


发布时间:2009/2/27 12:11:59  阅读次数:4095

2006 - 2024,推荐分辨率1024*768以上,推荐浏览器Chrome、Edge等现代浏览器,截止2021年12月5日的访问次数:1872万9823 站长邮箱

沪ICP备18037240号-1

沪公网安备 31011002002865号