【问题标题】:xna 4.0 how to have foreground texture transparent to show background texturexna 4.0 如何使前景纹理透明以显示背景纹理
【发布时间】:2012-06-10 22:36:24
【问题描述】:

我希望这是一个简单的问题和答案,但是 xna 和 microsoft 似乎不必要地使事情复杂化。

我有一个覆盖整个屏幕的背景纹理。然后我有一个前景纹理,我想在背景纹理上绘制。如您所料,前景纹理具有透明区域。我遇到的问题是,无论前景纹理是透明的,我都会看到蓝色的图形设备颜色而不是背景图像。

我已经找到了更多信息。我正在调整前景纹理的大小,似乎调整大小是造成悲伤的原因。

非常感谢任何建议或指示。

Draw(...)
{
ScreenManager.Game.GraphicsDevice.Clear(Color.DarkBlue);
SpriteBatch spriteBatch = this.ScreenManager.SpriteBatch;
spriteBatch.Begin();

// draw the background
spriteBatch.Draw(_backgroundTexture, _backgroundPosition, null, Color.White, 0f,
                 Vector2.Zero, 1.0f, SpriteEffects.None, 0f);
spriteBatch.Draw(Resize(_foregroundTexture,100,100), _foregroundPosition, null, Color.White, 0f,
                 Vector2.Zero, 1.0f, SpriteEffects.None, 0f);

spriteBatch.End();
}

Texture2D Resize(texture2D, float newWidth, float newHeight)
{
RenderTarget2D renderTarget;
Rectangle destinationRectangle;
SpriteBatch spriteBatch;

renderTarget = new RenderTarget2D(graphicsDevice, (int)newWidth, (int)newHeight);
destinationRectangle = new Rectangle(0, 0, (int)newWidth, (int)newHeight);
spriteBatch = new SpriteBatch(graphicsDevice);

graphicsDevice.SetRenderTarget(renderTarget);

spriteBatch.Begin();
spriteBatch.Draw(texture2D, destinationRectangle, Color.White);
spriteBatch.End();

graphicsDevice.SetRenderTarget(null);

return renderTarget;
}

【问题讨论】:

    标签: c# xna transparency xna-4.0


    【解决方案1】:

    当我调整大小时,我需要指定以下精灵批处理参数...

    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-30
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多