0
我希望這是一個簡單的問題和答案,但隨後XNA和微軟似乎不必要的事情複雜化。XNA 4.0如何有前景的質地透明,顯示背景紋理
我有一個背景紋理覆蓋整個屏幕。然後,我想要在背景紋理上繪製前景紋理。正如您所料,前景紋理具有透明區域。 ,我有問題是,徘徊無論前景質地是透明的,我看到的藍色,而不是背景圖像的圖形設備的顏色。
我已經找到了更多的信息。我調整前景質地,似乎調整大小是什麼原因造成的悲痛。
任何建議或指針十分讚賞。
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;
}