Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there an alpha value that makes white go invisible?
    text
    copied!<p>If I use the following</p> <pre><code>for(int i = 255; i &gt; 0; i--) { Color transparentBlack = new Color(0, 0, 0, i); } </code></pre> <p>I have the effect of the object using this color to draw with going from black to a light grey and then invisible when the alpha value goes to zero. However if I start with a white value:</p> <pre><code>new Color(255, 255, 255, i); </code></pre> <p>The objects never becomes invisible and only stays white. I've also noticed that if I use a value that is a bit lighter than black (say 50, 50, 50) the drawing goes from Dark, to invisible, to White.</p> <p>I assume that I just don't understand how alpha blending mixing works but is there a way of making a white color fade to translucency? </p> <p>Edit: The background I am drawing on is Color.CornflowerBlue (100,149,237,255)</p> <p>Edit: Sample XNA program reproducing the explanation. To use; create a new XNA Game Studio 4.0 project - Windows Game (4.0), call it AlphaBlendTest - &amp; In the content project add a new SpriteFont and call it testfont </p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace AlphaBlendTest { /// &lt;summary&gt; /// This is the main type for your game /// &lt;/summary&gt; public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; SpriteFont font; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// &lt;summary&gt; /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// &lt;/summary&gt; protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } /// &lt;summary&gt; /// LoadContent will be called once per game and is the place to load /// all of your content. /// &lt;/summary&gt; protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load&lt;SpriteFont&gt;("testfont"); } /// &lt;summary&gt; /// UnloadContent will be called once per game and is the place to unload /// all content. /// &lt;/summary&gt; protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// &lt;summary&gt; /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// &lt;/summary&gt; /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here base.Update(gameTime); } /// &lt;summary&gt; /// This is called when the game should draw itself. /// &lt;/summary&gt; /// &lt;param name="gameTime"&gt;Provides a snapshot of timing values.&lt;/param&gt; protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); //spriteBatch.Draw(tR, new Rectangle(100, 100, 100, 100), Color.Red); Vector2 v2 = new Vector2(0, 0); spriteBatch.DrawString(font, "Test - White", v2, Color.White); v2.Y = v2.Y + 50; spriteBatch.DrawString(font, "Test - Black", v2, Color.Black); v2.Y = v2.Y + 50; Color BlackTransparent = new Color(0, 0, 0, 0); spriteBatch.DrawString(font, "Test - Black Transparent", v2, BlackTransparent); v2.Y = v2.Y + 50; Color WhiteTransparent = new Color(255, 255, 255, 0); spriteBatch.DrawString(font, "Test - White Transparent", v2, WhiteTransparent); spriteBatch.End(); base.Draw(gameTime); } } } </code></pre> <p>Edit: This is the image this code draws: <img src="https://i.stack.imgur.com/Y64zL.png" alt="alt text"></p> <p>Edit: One of the comments is concerned that this is a Text only related 'feature' of windows. I used text as an example to keep the demo program small; testing with an image gives the same result. <img src="https://i.stack.imgur.com/ibI7t.png" alt="alt text"></p> <p>To add the square box in to the demo program; create a square white PNG image and add it to the content directory (use the default values for the content pipeline). Then add this to the class:</p> <pre><code>Texture2D tWhiteBox; </code></pre> <p>Add this in to the load method:</p> <pre><code>tWhiteBox = Content.Load&lt;Texture2D&gt;("whitebox"); </code></pre> <p>Then in the draw add the following below the other draw statements:</p> <pre><code>v2.Y = v2.Y + 50; spriteBatch.Draw(tWhiteBox, v2, WhiteTransparent); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload