UEXDev

Texture2D Generierung

May 8th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. void BuildCompleteTexture(GraphicsDevice device)
  2. {
  3.     int dim = gridSize * tileSize;
  4.  
  5.     // Wir erzeugen eine blanke Textur in der Größe des Applikationsfensters
  6.     Texture2D map = new Texture2D(device, dim, dim);
  7.  
  8.     for (int row = 0; row < gridSize; row++)
  9.     {
  10.         for (int col = 0; col < gridSize; col++)
  11.         {
  12.             // wir holen uns die Farbe des Terrains
  13.             byte terrainType = (byte)noiseMap.GetMapValue(row, col);
  14.  
  15.             // definieren ein Rechteck in der richtigen Größe
  16.             Rectangle rect = new Rectangle(row * tileSize, col * tileSize, tileSize, tileSize);
  17.            
  18.             Color color = TileMap[row, col];
  19.  
  20.             Color[] arr = new Color[tileSize * tileSize];
  21.             for (int i = 0; i < tileSize * tileSize; i++)
  22.                 arr[i] = color;
  23.  
  24.             // und zeichnen die Farbe in der Größe des Rechtecks sie an die richtige Stelle auf der blanken Textur
  25.             map.SetData<Color>(0, rect, arr, 0, tileSize * tileSize);
  26.         }
  27.     }
  28.  
  29.     Texture = map;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment