示例#1
0
        public Texture2D MirrorTexture(ISprite sprite, GraphicsDeviceManager graphics, Texture2D texture)
        {
            Texture2D mirroredProjectile = new Texture2D(graphics.GraphicsDevice, sprite.GetSpriteWidth(), sprite.GetSpriteHeight());

            Color[] projectileTextureHelper = new Color[sprite.GetSpriteWidth() * sprite.GetSpriteHeight()];
            Color[] newTextureData          = new Color[sprite.GetSpriteWidth() * sprite.GetSpriteHeight()];
            texture.GetData <Color>(
                0, sprite.GetSourceRect(), projectileTextureHelper, 0, sprite.GetSpriteWidth() * sprite.GetSpriteHeight());

            for (int x = 0; x < sprite.GetSpriteWidth(); x++)
            {
                for (int y = 0; y < sprite.GetSpriteHeight(); y++)
                {
                    newTextureData[y * sprite.GetSpriteWidth() + x]           = projectileTextureHelper[(y + 1) * sprite.GetSpriteWidth() - 1 - x];
                    newTextureData[(y + 1) * sprite.GetSpriteWidth() - 1 - x] = projectileTextureHelper[y * sprite.GetSpriteWidth() + x];
                }
            }

            mirroredProjectile.SetData <Color>(0, new Rectangle(0, 0, sprite.GetSpriteWidth(), sprite.GetSpriteHeight()), newTextureData, 0, sprite.GetSpriteWidth() * sprite.GetSpriteHeight());
            return(mirroredProjectile);
        }