Exemple #1
0
        /// <summary>
        /// Obtém o conteúdo de cores passando o frame (com o tamanho do data) e o Color data.
        /// </summary>
        /// <param name="frame">O recorte da textura.</param>
        /// <param name="data">O array de cores recebido da textura.</param>
        /// <param name="effects">Os efeitos a serem observados.</param>
        protected static Color[] GetData(Rectangle frame, Color[] data, SpriteEffects effects)
        {
            if (effects == SpriteEffects.None)
            {
                //Se não há transformação retorna o array recebido.
                return(data);
            }
            else
            {
                //Há transformação
                Color[,] colorArray = new Color[frame.Width, frame.Height];                     // Array multidimensional para representar uma imagem
                Vector2 position = Vector2.Zero;                                                // Posição do array
                int     index    = 0;                                                           // A posição no array colors

                Color[] final      = new Color[data.Length];                                    // O array a ser enviado no final
                int     finalIndex = 0;                                                         // O index para percorrer o array final

                if (effects == (SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically)) // | ou & ???
                {
                    position.X = frame.Width - 1;
                    position.Y = frame.Height - 1;
                    for (int h = 0; h < frame.Height; h++)
                    {
                        for (int w = 0; w < frame.Width; w++)
                        {
                            colorArray[(int)position.X, (int)position.Y] = data[index];
                            position.X -= 1;
                            index++;
                        }

                        position.Y -= 1;
                        position.X  = frame.Width - 1;
                    }
                }
                else if (effects == SpriteEffects.FlipHorizontally)
                {
                    position.X = frame.Width - 1;
                    for (int h = 0; h < frame.Height; h++)
                    {
                        for (int w = 0; w < frame.Width; w++)
                        {
                            colorArray[(int)position.X, (int)position.Y] = data[index];

                            position.X -= 1;
                            index++;
                        }

                        position.Y += 1;
                        position.X  = frame.Width - 1;
                    }
                }
                else if (effects == SpriteEffects.FlipVertically)
                {
                    position.Y = frame.Height - 1;
                    for (int h = 0; h < frame.Height; h++)
                    {
                        for (int w = 0; w < frame.Width; w++)
                        {
                            colorArray[(int)position.X, (int)position.Y] = data[index];

                            position.X += 1;
                            index++;
                        }

                        position.Y -= 1;
                        position.X  = 0;
                    }
                }

                //Para cada coluna percorremos as linhas do array multidimensional
                for (int c = 0; c < colorArray.GetLength(1); c++)
                {
                    for (int l = 0; l < colorArray.GetLength(0); l++)
                    {
                        final[finalIndex] = colorArray[l, c];
                        finalIndex++;
                    }
                }

                return(final);
            }
        }