예제 #1
0
        public Pixmap toPixmap()
        {
            var pixmap = new MonoGamePixmap(_regionWidth, _regionHeight);

            var texture2d            = ((MonoGameTexture)_texture).texture2D;
            var rawTextureRegionData = new Color[_regionWidth * _regionHeight];

            Rectangle boundingRect = new Rectangle(getRegionX(), getRegionY(), _regionWidth, _regionHeight);

            bool flipX = isFlipX();
            bool flipY = isFlipY();

            if (flipX)
            {
                boundingRect.X -= _regionWidth;
            }

            if (flipY)
            {
                boundingRect.Y -= _regionHeight;
            }

            texture2d.GetData(0, boundingRect, rawTextureRegionData, 0, _regionWidth * _regionHeight);
            for (var x = 0; x < _regionWidth; x++)
            {
                for (var y = 0; y < _regionHeight; y++)
                {
                    var actualX = x;
                    var actualY = y;
                    if (flipX)
                    {
                        actualX = _regionWidth - x;
                    }

                    if (flipY)
                    {
                        actualY = _regionHeight - y;
                    }
                    pixmap.drawPixel(actualX, actualY, MonoGameColor.toRGBA8888(rawTextureRegionData[x + y * _regionWidth]));
                }
            }

            return(pixmap);
        }
예제 #2
0
        public void drawPixel(int x, int y, UInt32 color, bool blend = true)
        {
            var colorAlpha = MonoGameColor.getAAsByte(color);

            if (x < getWidth() && y < getHeight() && x >= 0 && y >= 0 && colorAlpha > 0)
            {
                if (colorAlpha == 255 || !blend)
                {
                    _pixmap[x, y] = color;
                }
                else
                {
                    var newR = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha));
                    var newG = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha));
                    var newB = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha));
                    _pixmap[x, y] = MonoGameColor.toRGBA8888(newR, newG, newB, colorAlpha);
                }
            }
        }
예제 #3
0
        public void drawCircle(int centerX, int centerY, int radius)
        {
            if (radius <= 0)
            {
                return;
            }
            var color         = _setColor.toRGBA8888();
            int radiusSquared = radius * radius;

            drawPixel(centerX, centerY + radius, color);
            drawPixel(centerX, centerY - radius, color);
            drawPixel(centerX + radius, centerY, color);
            drawPixel(centerX - radius, centerY, color);

            var x = 1;
            var y = (int)(Math.Sqrt(radiusSquared - 1) + 0.5);

            while (x < y)
            {
                drawPixel(centerX + x, centerY + y, color);
                drawPixel(centerX + x, centerY - y, color);
                drawPixel(centerX - x, centerY + y, color);
                drawPixel(centerX - x, centerY - y, color);
                drawPixel(centerX + y, centerY + x, color);
                drawPixel(centerX + y, centerY - x, color);
                drawPixel(centerX - y, centerY + x, color);
                drawPixel(centerX - y, centerY - x, color);
                x += 1;
                y  = (int)(Math.Sqrt(radiusSquared - x * x) + 0.5);
            }
            if (x == y)
            {
                drawPixel(centerX + x, centerY + y, color);
                drawPixel(centerX + x, centerY - y, color);
                drawPixel(centerX - x, centerY + y, color);
                drawPixel(centerX - x, centerY - y, color);
            }
        }