3

this is a very difficult problem to describe (I'm using MonoGame, Windows 8).

I want to be able to render a semi-transparent 'sprite' image, such as a .png, not onto the screen but onto a clear image, do this several times to in effect create a new sprite image by blending together various images... then, I want to be able to render this new sprite image to the screen with the areas that I haven't drawn to remaining transparent (i.e. around the edge mainly).

Sure, I can load in a semi-transparent 'sprite' .png image and 'paste' it onto the RenderTarget; I can do this several times and the 'sprites' will blend nicely. I can then 'paste' (i.e. draw/render) that composite image, the RenderTarget, onto the screen.

The problem is, when the RenderTarget is drawn onto the screen, it has a solid block around it.

Presumably, the default alpha value for each pixel in the RenderTarget is solid. Any pixel that I don't draw to, I want to remain fully transparent, just as if you grabbed a paintbrush and painted not onto paper but onto glass. If you then placed that sheet of glass on, say, your swirly carpet, everywhere that doesn't have paint you would see swirly carpet. But that's not what I see, I just see black, as though I'd 'painted onto black paper' rather than 'painted onto glass'.

If I could render an image onto another image directly there wouldn't be a problem (can this be done?): I'd create an 'empty' .png image, perhaps in PhotoShop, i.e. not draw anything then save it with transparency enabled, and I'd render my images onto that, then save the result. But a RenderTarget seems to be already opaque.

I hope the above is clear. I've searched and found lots of answers on manipulating the alpha of Texture2D objects, but I can't find anything on manipulating the alpha of a RenderTarget2D.

Thanks for any help!

4

1 回答 1

2

我终于找到了解决方案,所以我将回答我自己的问题,以防它对其他人有用。

这很简单。实际上,您可以将 RenderTarget2D 变成透明的,因为它显然基本上是一个 Texture2D。你可以像这样清除它:

GraphicsDevice.Clear(Color.Transparent);

它似乎从默认情况下开始稳定,这让我感到困惑。

于 2015-03-29T12:36:55.107 回答