Ejemplo n.º 1
0
        internal void drawTexture(MonoGameTexture texture, float x, float y, int srcX, int srcY, int srcWidth,
                                  int srcHeight, float scaleX, float scaleY, float originX, float originY, float rotation, bool flipX,
                                  bool flipY, MonoGameColor tint)
        {
            beginRendering();
            if (texture.getUAddressMode() != _currentUMode || texture.getVAddressMode() != _currentVMode)
            {
                _currentUMode = texture.getUAddressMode();
                _currentVMode = texture.getVAddressMode();
                updateAddressMode();
            }


            _sharedPositionVector.X       = x - originX;
            _sharedPositionVector.Y       = y - originY;
            _sharedSourceRectangle.X      = srcX;
            _sharedSourceRectangle.Y      = srcY;
            _sharedSourceRectangle.Width  = srcWidth;
            _sharedSourceRectangle.Height = srcHeight;
            _sharedOriginVector.X         = originX;
            _sharedOriginVector.Y         = originY;
            _sharedScaleVector.X          = scaleX;
            _sharedScaleVector.Y          = scaleY;

            _spriteBatch.Draw(texture.texture2D, _sharedPositionVector, _sharedSourceRectangle, tint._color,
                              MonoGameMathsUtil.degreeToRadian(rotation), _sharedOriginVector, _sharedScaleVector,
                              (flipX ? SpriteEffects.FlipHorizontally : SpriteEffects.None) |
                              (flipY ? SpriteEffects.FlipVertically : SpriteEffects.None), 0f);
        }
Ejemplo n.º 2
0
        public void drawSprite(Sprite sprite, float x, float y)
        {
            beginRendering();
            if (sprite.getTexture().getUAddressMode() != _currentUMode || sprite.getTexture().getVAddressMode() != _currentVMode)
            {
                _currentUMode = sprite.getTexture().getUAddressMode();
                _currentVMode = sprite.getTexture().getVAddressMode();
                updateAddressMode();
            }

            _sharedPositionVector.X       = x + sprite.getOriginX();
            _sharedPositionVector.Y       = y + sprite.getOriginY();
            _sharedSourceRectangle.X      = sprite.getRegionX();
            _sharedSourceRectangle.Y      = sprite.getRegionY();
            _sharedSourceRectangle.Width  = sprite.getRegionWidth();
            _sharedSourceRectangle.Height = sprite.getRegionHeight();
            _sharedOriginVector.X         = sprite.getOriginX();
            _sharedOriginVector.Y         = sprite.getOriginY();
            _sharedScaleVector.X          = sprite.getScaleX();
            _sharedScaleVector.Y          = sprite.getScaleY();

            _spriteBatch.Draw(((MonoGameTexture)sprite.getTexture()).texture2D, _sharedPositionVector,
                              _sharedSourceRectangle, ((MonoGameColor)sprite.getTint())._color,
                              MonoGameMathsUtil.degreeToRadian(((MonoGameSprite)sprite).getTotalRotation()),
                              _sharedOriginVector, _sharedScaleVector, (sprite.isFlipX() ? SpriteEffects.FlipHorizontally : SpriteEffects.None) |
                              (sprite.isFlipY() ? SpriteEffects.FlipVertically : SpriteEffects.None), 0f);
        }
Ejemplo n.º 3
0
        private Matrix createTransformationMatrix()
        {
            var scaledRotationCenterX = _rotationCenter.X * _scale.X;
            var scaledRotationCenterY = _rotationCenter.Y * _scale.Y;
            var scaledTranslationX    = _translation.X * _scale.X;
            var scaledTranslationY    = _translation.Y * _scale.Y;

            return(Matrix.CreateScale(_scale.X, _scale.Y, 1) *
                   Matrix.CreateTranslation(-scaledRotationCenterX, -scaledRotationCenterY, 0) *
                   Matrix.CreateRotationZ(MonoGameMathsUtil.degreeToRadian(_rotation)) *
                   Matrix.CreateTranslation(scaledRotationCenterX - scaledTranslationX, scaledRotationCenterY - scaledTranslationY, 0));
        }
Ejemplo n.º 4
0
        public void drawSprite(Sprite sprite, float x, float y)
        {
            var sourceRectangle = new Rectangle(sprite.getRegionX(), sprite.getRegionY(), sprite.getRegionWidth(), sprite.getRegionHeight());

            if (sprite.isFlipX())
            {
                sourceRectangle.X -= sourceRectangle.Width * 2;
            }

            if (sprite.isFlipY())
            {
                sourceRectangle.Y -= sourceRectangle.Height * 2;
            }
            var origin = new Vector2(sprite.getOriginX(), sprite.getOriginY());

            _spriteBatch.Draw(((MonoGameTexture)sprite.getTexture()).texture2D,
                              (new Vector2(x, y) + _translation + origin - _rotationCenter) * _scale, sourceRectangle,
                              ((MonoGameColor)sprite.getTint()).toMonoGameColor(),
                              MonoGameMathsUtil.degreeToRadian(((MonoGameSprite)sprite).getTotalRotation()), origin,
                              new Vector2(sprite.getScaleX(), sprite.getScaleY()) * _scale,
                              (sprite.isFlipX() ? SpriteEffects.FlipHorizontally : SpriteEffects.None) |
                              (sprite.isFlipY() ? SpriteEffects.FlipVertically : SpriteEffects.None), 0f);
        }
Ejemplo n.º 5
0
 internal void beginSpriteBatch()
 {
     _spriteBatch.Begin(SpriteSortMode.Deferred, _currentBlending, transformMatrix: Matrix.CreateRotationZ(MonoGameMathsUtil.degreeToRadian(_rotation)) * Matrix.CreateTranslation(new Vector3((_rotationCenter + _translation) * _scale, 0)), effect: _currentShader, rasterizerState: _rasterizerState, samplerState: _samplerState);
     _beginSpriteBatchCalled = true;
 }
Ejemplo n.º 6
0
 internal void beginSpriteBatch()
 {
     _spriteBatch.Begin(SpriteSortMode.Deferred, _blendState, transformMatrix: Matrix.CreateRotationZ(MonoGameMathsUtil.degreeToRadian(_rotation)) * Matrix.CreateTranslation(new Vector3((_rotationCenter + _translation) * _scale, 0)));
 }