Esempio n. 1
0
        public static Texture2D Rotate(this Texture2D texture, int numberOfTurns)
        {
            //The dimensions of the original texture
            int width = texture.Width, height = texture.Height;

            //Create a new array for the colour data, extract it from the image, then make a 2D array from it
            Color[] colourData = new Color[width * height];
            texture.GetData(colourData);
            Color[,] colourMatrix = colourData.to2DArray(width, height);

            //Rotate it numberOfTurns
            for (int i = 0; i < numberOfTurns; i++)
            {
                colourMatrix = colourMatrix.RotateClockWise();
            }

            //Make a new texture from the data and return it
            Texture2D returnTexture = new Texture2D(texture.GraphicsDevice, colourMatrix.GetLength(0), colourMatrix.GetLength(1));

            returnTexture.SetData(colourMatrix.to1DArray());
            return(returnTexture);
        }