Created
November 21, 2019 16:57
-
-
Save fdrobidoux/a1a0e3887702d8529c9b967f5b446c44 to your computer and use it in GitHub Desktop.
[MonoGame] Texture2D Helper - Fill texture's transparent area with a color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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