Пример #1
0
        private void SetEdgeBounds()
        {
            var _leftTop = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(0, 0, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(Bounds.X,
                                                  Bounds.Y,
                                                  (int)(Texture.Width / 2 * _sourceScale),
                                                  (int)(Texture.Height / 2 * _sourceScale))
            };

            var _rightTop = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(0, 0, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(Bounds.Right,
                                                  Bounds.Y,
                                                  (int)(Texture.Width / 2 * _sourceScale),
                                                  (int)(Texture.Height / 2 * _sourceScale)),
                Effect = SpriteEffects.FlipHorizontally
            };

            _rightTop.PositionRectangle.Offset(-_rightTop.PositionRectangle.Width, 0);

            var _leftBottom = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(0, 0, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(Bounds.X,
                                                  Bounds.Bottom,
                                                  (int)(Texture.Width / 2 * _sourceScale),
                                                  (int)(Texture.Height / 2 * _sourceScale)),
                Effect = SpriteEffects.FlipVertically
            };

            _leftBottom.PositionRectangle.Offset(0, -_leftBottom.PositionRectangle.Height);

            var _rightBottom = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(0, 0, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(Bounds.Right,
                                                  Bounds.Bottom,
                                                  (int)(Texture.Width / 2 * _sourceScale),
                                                  (int)(Texture.Height / 2 * _sourceScale)),
                Effect = SpriteEffects.FlipVertically | SpriteEffects.FlipHorizontally
            };

            _rightBottom.PositionRectangle.Offset(-_rightBottom.PositionRectangle.Width, -_rightBottom.PositionRectangle.Height);

            _spriteRect.Add(_leftBottom);
            _spriteRect.Add(_leftTop);
            _spriteRect.Add(_rightBottom);
            _spriteRect.Add(_rightTop);
        }
Пример #2
0
        private void SetSideBounds()
        {
            var _leftSide = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(0, Texture.Height / 2, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(Bounds.X,
                                                  _spriteRect[1].PositionRectangle.Bottom,
                                                  (int)(Texture.Width / 2 * _sourceScale),
                                                  Bounds.Height - (int)(Texture.Height * _sourceScale)),
                Effect = SpriteEffects.None
            };


            var _rightSide = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(0, Texture.Height / 2, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(_spriteRect[3].PositionRectangle.X,
                                                  _spriteRect[1].PositionRectangle.Bottom,
                                                  (int)(Texture.Width / 2 * _sourceScale),
                                                  Bounds.Height - (int)(Texture.Height * _sourceScale)),
                Effect = SpriteEffects.FlipHorizontally
            };


            var _topSide = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(Texture.Width / 2, 0, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(
                    _spriteRect[1].PositionRectangle.Right,
                    _spriteRect[1].PositionRectangle.Top,
                    Bounds.Width - (int)(Texture.Width * _sourceScale),
                    (int)(Texture.Height / 2 * _sourceScale)),
                Effect = SpriteEffects.None,
            };

            var _bottomSide = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(Texture.Width / 2, 0, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(
                    _spriteRect[1].PositionRectangle.Right,
                    _spriteRect[0].PositionRectangle.Top,
                    Bounds.Width - (int)(Texture.Width * _sourceScale),
                    (int)(Texture.Height / 2 * _sourceScale)),
                Effect = SpriteEffects.FlipVertically,
            };

            var _center = new SpriteRectangleSource(Texture)
            {
                SourceRectangle   = new Rectangle(Texture.Width / 2, Texture.Height / 2, Texture.Width / 2, Texture.Height / 2),
                PositionRectangle = new Rectangle(
                    _spriteRect[1].PositionRectangle.Right,
                    _spriteRect[1].PositionRectangle.Bottom,
                    Bounds.Width - (int)(Texture.Width * _sourceScale),
                    Bounds.Height - (int)(Texture.Height * _sourceScale)),
            };

            //_topSide.PositionRectangle.Offset(0, 0);
            _spriteRect.Add(_leftSide);
            _spriteRect.Add(_rightSide);
            _spriteRect.Add(_topSide);
            _spriteRect.Add(_bottomSide);
            _spriteRect.Add(_center);
        }