Skip to content

Instantly share code, notes, and snippets.

@fdrobidoux
Created November 21, 2019 16:57
Show Gist options
  • Save fdrobidoux/a1a0e3887702d8529c9b967f5b446c44 to your computer and use it in GitHub Desktop.
Save fdrobidoux/a1a0e3887702d8529c9b967f5b446c44 to your computer and use it in GitHub Desktop.
[MonoGame] Texture2D Helper - Fill texture's transparent area with a color
public static class TextureHelper
{
public static Texture2D FillMaskColor(this GraphicsDevice device, Texture2D mask, Color color)
{
Texture2D _texture = new Texture2D(device, mask.Width, mask.Height);
Color[] _buttonData = new Color[mask.Width * mask.Height];
Color[] _maskData = new Color[mask.Width * mask.Height];
mask.GetData(_maskData);
for (Int32 i = 0; i < _maskData.Length; ++i)
{
_buttonData[i] = _maskData[i];
if (_buttonData[i].A >= 200)
{
_buttonData[i] = color;
}
}
_texture.SetData(_buttonData);
return _texture;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment