public void draw(org.mini2Dx.core.Graphics g, float x, float y, float width, float height)
        {
            var xCount     = (int)(width / _textureRegion.getRegionWidth());
            var yCount     = (int)(height / _textureRegion.getRegionHeight());
            var xRemainder = width - xCount * _textureRegion.getRegionWidth();
            var yRemainder = height - yCount * _textureRegion.getRegionHeight();

            TextureRegion xRemainderRegion  = null;
            TextureRegion yRemainderRegion  = null;
            TextureRegion xyRemainderRegion = null;

            if (xRemainder != 0)
            {
                xRemainderRegion = new MonoGameTextureRegion(_textureRegion, (int)xRemainder, _textureRegion.getRegionHeight());
            }

            if (yRemainder != 0)
            {
                yRemainderRegion = new MonoGameTextureRegion(_textureRegion, _textureRegion.getRegionWidth(), (int)yRemainder);
            }

            if (xRemainder != 0 && yRemainder != 0)
            {
                xyRemainderRegion = new MonoGameTextureRegion(_textureRegion, (int)xRemainder, (int)yRemainder);
            }

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    g.drawTextureRegion(_textureRegion, x + _textureRegion.getRegionWidth() * i, y + j * _textureRegion.getRegionHeight());
                }
            }

            if (xRemainderRegion != null)
            {
                for (int i = 0; i < yCount; i++)
                {
                    g.drawTextureRegion(xRemainderRegion, x + xCount * _textureRegion.getRegionWidth(), y + i * _textureRegion.getRegionHeight());
                }
            }

            if (yRemainderRegion != null)
            {
                for (int i = 0; i < xCount; i++)
                {
                    g.drawTextureRegion(yRemainderRegion, x + i * _textureRegion.getRegionWidth(), y + yCount * _textureRegion.getRegionHeight());
                }
            }

            if (xyRemainderRegion != null)
            {
                g.drawTextureRegion(xyRemainderRegion, x + xCount * _textureRegion.getRegionWidth(), y + yCount * _textureRegion.getRegionHeight());
            }
        }
Пример #2
0
 private static void draw(org.mini2Dx.core.Graphics g, TextureRegion ninePatchRegion, float dstX, float dstY, float dstWidth, float dstHeight)
 {
     g.drawTextureRegion(ninePatchRegion, dstX, dstY, dstWidth, dstHeight);
 }