0
votes

i'm hoping this is a simple question and answer, but then xna and microsoft seem to complicate things needlessly.

I have a background texture that covers the entire screen. I then have a foreground texture that I want to draw ontop of the background texture. As you can expect, the foreground texture has transparent areas. the problem that i have is that whereever the foreground texture is transparent, I see the graphic device color of blue and not the background image.

I have tracked down further information. I am resizing the foreground texture and it seems that the resize is what is causing the grief.

Any suggestions or pointers are well appreciated.

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;
}
1

1 Answers

0
votes

when i resize, i need to specify the following sprite batch parameters...

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