Don't like ads? PRO users don't see any ads ;-)
Guest

ColorSwap()

By: a guest on Aug 28th, 2012  |  syntax: C#  |  size: 0.57 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public static Texture2D ColorSwap(string textureName, Dictionary<Color, Color> colorMap) {
  2.         Texture2D cachedTexture = ContentLoader.LoadTexture(textureName);
  3.  
  4.         Texture2D colorSwappedTexture = new Texture2D(Pigeon.Graphics.GraphicsDevice, cachedTexture.Width, cachedTexture.Height);
  5.  
  6.         Color[] data = new Color[cachedTexture.Width * cachedTexture.Height];
  7.         cachedTexture.GetData(data);
  8.  
  9.         for (int i = 0; i < data.Length; i++) {
  10.                 if (colorMap.ContainsKey(data[i])) {
  11.                         data[i] = colorMap[data[i]];
  12.                 }
  13.         }
  14.  
  15.         colorSwappedTexture.SetData(data);
  16.         return colorSwappedTexture;
  17. }