Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 10. 2D Effects > Blending Mode Example

Blending Mode Example

We will use the preceding code and tweak it a little bit to show some interesting blending effects. Let’s replace the contents of our previous Draw method with the following code:

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate,
    SaveStateMode.None);
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.DestinationColor;
graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.SourceColor;
spriteBatch.Draw(circular, destination, source, Color.White, rotation, origin,
    SpriteEffects.None, 0.0f);
spriteBatch.End();

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate,
    SaveStateMode.None);
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.One;
graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One;
spriteBatch.Draw(circular, new Vector2(600, 100), null, Color.White, -rotation,
    new Vector2(256, 256), scale, SpriteEffects.None, 0.0f);
spriteBatch.End();

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate,
    SaveStateMode.None);
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.DestinationColor;
graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.SourceAlpha;
spriteBatch.Draw(circular, new Vector2(100,600), null, Color.White, -rotation,
    new Vector2(256,256), scale, SpriteEffects.None, 0.0f);
spriteBatch.End();

spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate,
    SaveStateMode.None);
graphics.GraphicsDevice.RenderState.SourceBlend = Blend.InverseSourceColor;
graphics.GraphicsDevice.RenderState.DestinationBlend =
    Blend.InverseDestinationColor;
spriteBatch.Draw(circular, new Vector2(300, 300), null, Color.White, -rotation,
    new Vector2(0, 0), scale, SpriteEffects.None, 0.0f);
spriteBatch.End();


					  


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint