2011-06-12 76 views
2

嗨我試圖從this question 使用Alpha混合時使一部分紋理透明的答案唯一的問題是,這隻適用於XNA 3.1和I在XNA 4.0中工作,所以像RenderState這樣的東西不存在於相同的上下文中,我不知道在哪裏可以找到GfxComponent類庫。XNA Alpha在Game Studio 4.0中混合紋理的一部分

我仍然想要做與示例問題相同的事情,從鼠標位置發出一個圓形區域,當鼠標懸停在其上時,覆蓋紋理會變得透明。

+0

就個人而言,我會使用一個像素着色器,您將鼠標位置傳遞給它,以在繪製原始紋理時添加透明度。你也可以做各種混合欺騙。或者你可以通過渲染目標。 – 2011-06-15 01:50:40

回答

2

3.5

GraphicsDevice.RenderState.AlphaBlendEnable = true; 

4.0

GraphicsDevice.BlendState = BlendState.AlphaBlend; 

見肖恩·哈格里夫斯後獲得更多信息:http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx

編輯:在後,你可以用肖恩看到BlendState。您可以創建一個新的實例,然後按照您的喜好進行設置,然後將其傳遞給圖形設備。像這樣:

BlendState bs = new BlendState(); 
bs.AlphaSourceBlend = Blend.One; 
bs.AlphaDestinationBlend = Blend.Zero; 
bs.ColorSourceBlend = Blend.Zero; 
bs.ColorDestinationBlend = Blend.One; 
bs.AlphaBlendFunction = BlendFunction.Add; 
graphicsDevice.BlendState = bs; 

那更清晰?

+0

這並不完全有用,你知道。 – ShadowsEdge19 2011-06-13 18:58:45

+0

好的,謝謝,我在 之間添加了spriteBatch.Begin(SpriteSortMode.Immediate,BlendState.Opaque); spriteBatch.Draw(background,new Rectangle(0,0,GraphicsDevice.Viewport.Width,GraphicsDevice.Viewport.Height),Color.White); ... spriteBatch.Draw(blank,flashlightArea,Color.White); spriteBatch.End(); 但是,空白紋理是不可見的,但它不會對它後面的圖像產生任何影響,因爲我想通過矩形的孔看到圖像後面的藍色背景。 – ShadowsEdge19 2011-06-13 23:13:02

+0

'GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.Immediate,BlendState.Opaque); spriteBatch.Draw(背景,新的Rectangle(0,0,GraphicsDevice.Viewport.Width,GraphicsDevice.Viewport.Height),Color.White);' ..your代碼... 'spriteBatch.Draw(空白,flashlightArea,Color.White); spriteBatch.End();' – ShadowsEdge19 2011-06-13 23:22:56