2014-10-11 54 views
1

我想要做的是使用spritesheet創建混合地形,將其保存爲紋理,然後將其傳遞到着色器以獲取其他效果。但是,我有渲染目標的一些問題:使用渲染目標時擺脫黑色背景

RenderTarget2D someNewTexture = new RenderTarget2D(GraphicsDevice, 256, 256); 

GraphicsDevice.SetRenderTarget(someNewTexture); 
GraphicsDevice.Clear(Color.Black); 

spriteBatch.Begin(); 
{ 
    // draw some stuff 
} 
spriteBatch.End(); 

GraphicsDevice.SetRenderTarget(null); 

顯然,這創造了一個黑色的背景與我在它上面的紋理。但是,當我真的將該紋理繪製到我的主場景上時,我不想要背景,只需要紋理(如果我不使用清晰,則使用默認的紫色)。我該如何解決?

回答

2

使用透明清澈的顏色:

GraphicsDevice.Clear(Color.TransparentBlack); 

如果您正確處理混合,將導致透明像素不被繪製。

+0

呃,就這麼簡單。我以爲我不得不擺弄BlendMode。 – 2014-10-11 12:44:46

+1

它顯然已經正確設置 – thumbmunkeys 2014-10-11 12:46:00