Example #1
0
        public void drawTextureRegion(TextureRegion textureRegion, float x, float y, float width, float height, float rotation)
        {
            beginRendering();

            if (textureRegion.getTexture().getUAddressMode() != _currentUMode || textureRegion.getTexture().getVAddressMode() != _currentVMode)
            {
                _currentUMode = textureRegion.getTexture().getUAddressMode();
                _currentVMode = textureRegion.getTexture().getVAddressMode();
                updateAddressMode();
            }

            _sharedSourceRectangle.X      = textureRegion.getRegionX();
            _sharedSourceRectangle.Y      = textureRegion.getRegionY();
            _sharedSourceRectangle.Width  = textureRegion.getRegionWidth();
            _sharedSourceRectangle.Height = textureRegion.getRegionHeight();
            _sharedPositionVector.X       = x;
            _sharedPositionVector.Y       = y;
            _sharedScaleVector.X          = width / textureRegion.getRegionWidth();
            _sharedScaleVector.Y          = height / textureRegion.getRegionHeight();

            _spriteBatch.Draw(((MonoGameTexture)textureRegion.getTexture()).texture2D, _sharedPositionVector,
                              _sharedSourceRectangle, _tint, rotation, Vector2.Zero, _sharedScaleVector,
                              (textureRegion.isFlipX() ? SpriteEffects.FlipHorizontally : SpriteEffects.None) |
                              (textureRegion.isFlipY() ? SpriteEffects.FlipVertically : SpriteEffects.None), 0f);
        }
        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());
            }
        }
 public MonoGameNinePatch(TextureRegion texture, int left, int right, int top, int bottom)
 {
     _textureRegion   = texture;
     _topHeight       = top;
     _leftWidth       = left;
     _middleWidth     = _textureRegion.getRegionWidth() - right - left;
     _rightWidth      = right;
     _middleHeight    = _textureRegion.getRegionHeight() - top - bottom;
     _bottomHeight    = bottom;
     _ninePatchRegion = new MonoGameTextureRegion(_textureRegion);
     _textureRegionX  = _textureRegion.getRegionX();
     _textureRegionY  = _textureRegion.getRegionY();
     _rightX          = _textureRegion.getRegionWidth() - right;
     _bottomY         = _textureRegion.getRegionHeight() - bottom;
 }
 public MonoGameNinePatch(TextureRegion texture, int left, int right, int top, int bottom)
 {
     _textureRegion = texture;
     _topHeight     = top;
     _leftWidth     = left;
     _middleWidth   = _textureRegion.getRegionWidth() - right;
     _rightWidth    = right;
     _middleHeight  = _textureRegion.getRegionHeight() - top - bottom;
     _bottomHeight  = bottom;
 }
        public void render(org.mini2Dx.core.Graphics g, float x, float y, float width, float height)
        {
            var newTint = _setColor.copy().multiply(g.getTint());
            var oldTint = g.getTint();

            g.setTint(newTint);

            _ninePatchRegion = new MonoGameTextureRegion(_textureRegion);

            _ninePatchRegion.setRegionX(0);
            _ninePatchRegion.setRegionY(0);
            _ninePatchRegion.setRegionWidth((int)_leftWidth);
            _ninePatchRegion.setRegionHeight((int)_topHeight);
            draw(g, _ninePatchRegion, x, y, _leftWidth, _topHeight);
            _ninePatchRegion.setRegionX((int)_leftWidth);
            _ninePatchRegion.setRegionWidth((int)(_textureRegion.getRegionWidth() - _leftWidth - _rightWidth));
            draw(g, _ninePatchRegion, x + _leftWidth, y, width - _leftWidth - _rightWidth, _topHeight);
            _ninePatchRegion.setRegionX((int)(_textureRegion.getRegionWidth() - _rightWidth));
            _ninePatchRegion.setRegionWidth((int)_rightWidth);
            draw(g, _ninePatchRegion, x + width - _rightWidth, y, _rightWidth, _topHeight);
            _ninePatchRegion.setRegionY((int)_topHeight);
            _ninePatchRegion.setRegionHeight((int)(_textureRegion.getRegionHeight() - _topHeight - _bottomHeight));
            draw(g, _ninePatchRegion, x + width - _rightWidth, y + _topHeight, _rightWidth, height - _topHeight - _bottomHeight);
            _ninePatchRegion.setRegionX((int)_leftWidth);
            _ninePatchRegion.setRegionWidth((int)(_textureRegion.getRegionWidth() - _leftWidth - _rightWidth));
            draw(g, _ninePatchRegion, x + _leftWidth, y + _topHeight, width - _leftWidth - _rightWidth, height - _topHeight - _bottomHeight);
            _ninePatchRegion.setRegionX(0);
            _ninePatchRegion.setRegionWidth((int)_leftWidth);
            draw(g, _ninePatchRegion, x, y + _topHeight, _leftWidth, height - _topHeight - _bottomHeight);
            _ninePatchRegion.setRegionY((int)(_textureRegion.getRegionHeight() - _bottomHeight));
            _ninePatchRegion.setRegionHeight((int)_bottomHeight);
            draw(g, _ninePatchRegion, x, y + height - _bottomHeight, _leftWidth, _bottomHeight);
            _ninePatchRegion.setRegionX((int)_leftWidth);
            _ninePatchRegion.setRegionWidth((int)(_textureRegion.getRegionWidth() - _leftWidth - _rightWidth));
            draw(g, _ninePatchRegion, x + _leftWidth, y + height - _bottomHeight, width - _leftWidth - _rightWidth, _bottomHeight);
            _ninePatchRegion.setRegionX((int)(_textureRegion.getRegionWidth() - _rightWidth));
            _ninePatchRegion.setRegionWidth((int)_rightWidth);
            draw(g, _ninePatchRegion, x + width - _rightWidth, y + height - _bottomHeight, _rightWidth, _bottomHeight);
            g.setTint(oldTint);
        }
Example #6
0
        public int add(TextureRegion region, float x, float y, float scaleX, float scaleY, float originX, float originY,
                       float rotation, bool flipX, bool flipY)
        {
            var operation = new SpriteCacheDrawingOperation
            {
                srcWidth  = region.getRegionWidth(),
                srcHeight = region.getRegionHeight(),
                dstX      = x,
                dstY      = y,
                scaleX    = scaleX,
                scaleY    = scaleY,
                originX   = originX,
                originY   = originY,
                rotation  = rotation,
                flipX     = flipX,
                flipY     = flipY,
                color     = _currentColor
            };

            add(region, out operation.srcX, out operation.srcY);
            _caches[_currentCache].operations.Add(operation);
            return(_caches[_currentCache].operations.Count - 1);
        }
Example #7
0
        public void drawTextureRegion(TextureRegion textureRegion, float x, float y, float width, float height, float rotation)
        {
            if (textureRegion.getTexture().getUAddressMode() != _currentUMode || textureRegion.getTexture().getVAddressMode() != _currentVMode)
            {
                _currentUMode = textureRegion.getTexture().getUAddressMode();
                _currentVMode = textureRegion.getTexture().getVAddressMode();
                updateAddressMode();
            }
            var sourceRectangle = new Rectangle(textureRegion.getRegionX(), textureRegion.getRegionY(), textureRegion.getRegionWidth(), textureRegion.getRegionHeight());

            if (textureRegion.isFlipX())
            {
                sourceRectangle.X -= sourceRectangle.Width;
            }

            if (textureRegion.isFlipY())
            {
                sourceRectangle.Y -= sourceRectangle.Height;
            }
            _spriteBatch.Draw(((MonoGameTexture)textureRegion.getTexture()).texture2D,
                              (new Vector2(x, y) + _translation - _rotationCenter) * _scale, sourceRectangle, _tint, rotation, Vector2.Zero,
                              new Vector2(width / textureRegion.getRegionWidth(), height / textureRegion.getRegionHeight()) *
                              _scale, (textureRegion.isFlipX() ? SpriteEffects.FlipHorizontally : SpriteEffects.None) |
                              (textureRegion.isFlipY() ? SpriteEffects.FlipVertically : SpriteEffects.None), 0f);
        }
Example #8
0
 public void drawTextureRegion(TextureRegion textureRegion, float x, float y)
 {
     drawTextureRegion(textureRegion, x, y, textureRegion.getRegionWidth(), textureRegion.getRegionHeight());
 }
Example #9
0
 private void add(TextureRegion region, out int posX, out int posY)
 {
     add(region.getTexture(), region.getRegionX(), region.getRegionY(), region.getRegionWidth(), region.getRegionHeight(), out posX, out posY);
 }
Example #10
0
 public MonoGameSprite(TextureRegion region) : this(region, region.getRegionWidth(), region.getRegionHeight())
 {
 }