我希望这是一个简单的问题和答案,但是 xna 和微软似乎不必要地使事情复杂化。
我有一个覆盖整个屏幕的背景纹理。然后我有一个前景纹理,我想在背景纹理上绘制。如您所料,前景纹理具有透明区域。我遇到的问题是,无论前景纹理是透明的,我都会看到蓝色的图形设备颜色,而不是背景图像。
我已经追踪了更多信息。我正在调整前景纹理的大小,似乎调整大小是造成悲伤的原因。
任何建议或指示都非常感谢。
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;
}