Exemple #1
0
        /// <summary>
        /// attempts to load and draw the SvgImage. If it cannot load a Texture it will just draw a rect.
        /// </summary>
        /// <param name="batcher">Batcher.</param>
        /// <param name="images">Images.</param>
        void RenderImages(Batcher batcher, SvgImage[] images)
        {
            if (images == null)
            {
                return;
            }

            foreach (var image in images)
            {
                var tex = image.GetTexture(Entity.Scene.Content);
                if (tex != null)
                {
                    var rotation = image.RotationDegrees * Mathf.Deg2Rad;
                    if (rotation == 0)
                    {
                        batcher.Draw(tex, image.Rect);
                    }
                    else
                    {
                        var rect   = image.Rect;
                        var origin = new Vector2(0.5f * rect.Width, 0.5f * rect.Height);
                        rect.Location += origin;

                        batcher.Draw(tex, rect, null, Color.White, rotation, origin, SpriteEffects.None, LayerDepth);
                    }
                }
                else
                {
                    batcher.DrawRect(image.X, image.Y, image.Width, image.Height, Color.DarkRed);
                }
            }
        }
Exemple #2
0
        public override void Render(Batcher batcher, Camera camera)
        {
            var cellSize = new Point(map.TileWidth, map.TileHeight);
            // FIXME: how to get tiled offset
            var tiledOffset = Core.Scene.FindEntity(EntityNames.tiled).Position.ToPoint();

            // settings
            var rect      = new SpriteData(Graphics.Instance.PixelTexture, cellSize, cellSize);
            var grid      = new SpriteData(Graphics.Instance.PixelTexture, cellSize - new Point(4, 4), cellSize);
            var gridColor = Color.WhiteSmoke * 0.25f;

            // copied from TiledRendering class
            var bounds = camera.Bounds;
            var scale  = new Vector2(1, 1);
            var minX   = this.map.WorldToTilePositionX(bounds.Left - (this.map.MaxTileWidth * scale.X - map.TileWidth));
            var minY   = this.map.WorldToTilePositionY(bounds.Top - (this.map.MaxTileHeight * scale.Y - map.TileHeight));
            var maxX   = this.map.WorldToTilePositionX(bounds.Right + (this.map.MaxTileWidth * scale.X - map.TileWidth));
            var maxY   = this.map.WorldToTilePositionY(bounds.Bottom + (this.map.MaxTileHeight * scale.Y - map.TileHeight));

            for (var y = minY; y <= maxY; y++)
            {
                for (var x = minX; x <= maxX; x++)
                {
                    var pos = new Point(x * cellSize.X, y * cellSize.Y);

                    if (this.fow.isCovered(x, y))
                    {
                        // hide the cell
                        // var color = Color.Black * 0.9f;
                        var color    = Color.Black;
                        var destRect = new Rectangle(pos.X + rect.offset.X, pos.Y + rect.offset.Y, rect.size.X, rect.size.Y);
                        destRect.Offset(tiledOffset); // FIXME
                        batcher.Draw(rect.sprite, destRect, rect.sprite.SourceRect, color,
                                     this.Entity.Transform.Rotation, SpriteEffects.None, this.LayerDepth,
                                     0f, 0f, 0f, 0f
                                     );
                        continue;
                    }

                    // draw grid to visible & walkable cells
                    if (this.fov.canSee(x, y) && !this.stage.isBlocked(x, y))
                    {
                        var destRect = new Rectangle(pos.X + grid.offset.X, pos.Y + grid.offset.Y, grid.size.X, grid.size.Y);
                        destRect.Offset(tiledOffset); // FIXME
                        batcher.DrawHollowRect(destRect, gridColor);
                    }

                    { // draw shadow
                        var color    = Color.Black * this.getAlphaAt(x, y);
                        var destRect = new Rectangle(pos.X + rect.offset.X, pos.Y + rect.offset.Y, rect.size.X, rect.size.Y);
                        destRect.Offset(tiledOffset); // FIXME
                        batcher.Draw(rect.sprite, destRect, rect.sprite.SourceRect, color,
                                     this.Entity.Transform.Rotation, SpriteEffects.None, this.LayerDepth,
                                     0f, 0f, 0f, 0f
                                     );
                    }
                }
            }
        }
Exemple #3
0
        public override void Draw(Batcher batcher, float x, float y, float width, float height, Color color)
        {
            float regionWidth = Sprite.SourceRect.Width, regionHeight = Sprite.SourceRect.Height;
            int   fullX = (int)(width / regionWidth), fullY = (int)(height / regionHeight);
            float remainingX = width - regionWidth * fullX, remainingY = height - regionHeight * fullY;
            float startX = x, startY = y;

            // draw all full, unclipped first
            for (var i = 0; i < fullX; i++)
            {
                y = startY;
                for (var j = 0; j < fullY; j++)
                {
                    batcher.Draw(Sprite, new System.Numerics.Vector2(x, y), Sprite.SourceRect, color);
                    y += regionHeight;
                }

                x += regionWidth;
            }

            var tempSourceRect = Sprite.SourceRect;

            if (remainingX > 0)
            {
                // right edge
                tempSourceRect.Width = (int)remainingX;
                y = startY;
                for (var ii = 0; ii < fullY; ii++)
                {
                    batcher.Draw(Sprite, new System.Numerics.Vector2(x, y), tempSourceRect, color);
                    y += regionHeight;
                }

                // lower right corner.
                tempSourceRect.Height = (int)remainingY;
                if (remainingY > 0)
                {
                    batcher.Draw(Sprite, new System.Numerics.Vector2(x, y), tempSourceRect, color);
                }
            }

            tempSourceRect.Width = Sprite.SourceRect.Width;
            if (remainingY > 0)
            {
                // bottom edge
                tempSourceRect.Height = (int)remainingY;
                x = startX;
                for (var i = 0; i < fullX; i++)
                {
                    batcher.Draw(Sprite, new System.Numerics.Vector2(x, y), tempSourceRect, color);
                    x += regionWidth;
                }
            }
        }
Exemple #4
0
        public void Draw(Batcher batcher, float x, float y, float width, float height, Color color)
        {
            if (TintColor.HasValue)
            {
                color = color.Multiply(TintColor.Value);
            }

            if (_finalRenderRect.Height != height || _finalRenderRect.Width != width)
            {
                _finalRenderRect.Height = (int)height;
                _finalRenderRect.Width  = (int)width;
                _sprite.GenerateNinePatchRects(_finalRenderRect, _destRects, _sprite.Left, _sprite.Right,
                                               _sprite.Top, _sprite.Bottom);
            }

            for (var i = 0; i < 9; i++)
            {
                // only draw if we have width/height to draw.
                if (_destRects[i].Width == 0 || _destRects[i].Height == 0)
                {
                    continue;
                }

                // shift our destination rect over to our position
                var dest = _destRects[i];
                dest.X += (int)x;
                dest.Y += (int)y;
                batcher.Draw(_sprite, dest, _sprite.NinePatchRects[i], color);
            }
        }
        public override void Draw(GameTime gameTime)
        {
            Batcher.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);
            //background
            Batcher.Draw(WhiteTexture, Window, BackgroundColor);
            //cursor
            int textY = Window.Y + Window.Height - font.LineSpacing;

            if (Activated)
            {
                Batcher.Draw(WhiteTexture, new Rectangle(Window.X + (int)font.MeasureString(line.ToString().Substring(0, CursorPosition)).X, textY, 2, font.LineSpacing), Color.White);
            }
            //command line
            Batcher.DrawString(font, line, new Vector2(Window.X, textY), Color.White);
            //output
            foreach (var outputLine in output.Lines.Reverse())
            {
                textY -= font.LineSpacing;

                if (textY < Window.Y)
                {
                    break;
                }
                Batcher.DrawString(font, outputLine, new Vector2(Window.X, textY), Color.White);
            }

            Batcher.End();

            base.Draw(gameTime);
        }
Exemple #6
0
 protected virtual void SceneFinalRender(Batcher batch, RenderTarget2D frame, RectangleF finalDestination)
 {
     Core.GraphicsDevice.SetRenderTarget(null);
     Core.GraphicsDevice.Clear(BackColor);
     batch.Begin(BlendState.Opaque, SamplerState.PointClamp, null, null);
     batch.Draw(frame, finalDestination);
     batch.End();
 }
Exemple #7
0
        public static void DrawTile(Batcher batcher, Point gridOffset, Point worldOffset, Tile tile, Color tint)
        {
            Point offset      = new Point(Constants.pixelsPerTile * gridOffset.X, -Constants.pixelsPerTile * gridOffset.Y);
            Point totalOffset = worldOffset + offset;
            var   texture     = Core.Scene.Content.LoadTexture(tile.spriteLocation);

            batcher.Draw(texture, new Rectangle(totalOffset.X, totalOffset.Y, Constants.pixelsPerTile, Constants.pixelsPerTile), tint);
        }
        private void DrawLine(Batcher batcher, Vector2 start, Vector2 end, Color color, float thickness = 2f)
        {
            var delta = end - start;
            var angle = (float)Math.Atan2(delta.Y, delta.X);

            batcher.Draw(Graphics.Instance.PixelTexture, start + Entity.Transform.Position + LocalOffset,
                         Graphics.Instance.PixelTexture.SourceRect, color, angle, new Vector2(0, 0.5f),
                         new Vector2(delta.Length(), thickness), SpriteEffects.None, LayerDepth);
        }
 public override void Render(Batcher batcher, Camera camera)
 {
     for (var x = this.playerCamera.TopLeftTileX; x < this.playerCamera.TopLeftTileX + this.playerCamera.WidthTiles; ++x)
     {
         for (var y = this.playerCamera.TopLeftTileY; y < this.playerCamera.TopLeftTileY + this.playerCamera.HeightTiles; ++y)
         {
             batcher.Draw(this.defaultTileTexture, new Vector2(x, y) * Tile.SpriteSize);
         }
     }
 }
Exemple #10
0
        public override void Render(Batcher batcher, Camera camera)
        {
            if (_sprite == null)
            {
                return;
            }

            var drawInfo = Entity.GetComponent <DrawInfo>();

            batcher.Draw(_sprite, drawInfo.Position, null, drawInfo.Color, drawInfo.Rotation, new Vector2(.5f), drawInfo.Size, SpriteEffects.None, 0f);
        }
Exemple #11
0
 public override void Render(Batcher batcher, Camera camera)
 {
     foreach (Cell cell in GameBoard.Instance.GetCells())
     {
         if (cell.piece == null)
         {
             continue;
         }
         Rectangle r = new Rectangle(GameBoard.BoardToWorld(cell.position), new Point(Constants.CellSize, Constants.CellSize));
         batcher.Draw(cell.piece.texture, r);
     }
 }
Exemple #12
0
 internal void Draw(Batcher batcher, Entity Entity)
 {
     batcher.Draw(
         Sprite,
         Entity.Position + Bounds.Location,
         Color.White,
         Entity.Rotation,
         Vector2.Zero,
         1.01f,
         SpriteEffects.None,
         0);
 }
Exemple #13
0
        public override void Render(Batcher batcher, Camera camera)
        {
#if DEBUG
            Tilerenders = 0;
#endif
            Rectangle dst = new Rectangle();
            for (int i = 0; i < RenderedLayers.Count; i++)
            {
                var layer = RenderedLayers[i];
                var tile  = TilesetLookup[layer.TileSet];
                dst.Width  = tile.TileSize.X;
                dst.Height = tile.TileSize.Y;

                var start = layer.WorldToTile(camera.Bounds.Location);
                var end   = layer.WorldToTile(camera.Bounds.Location + camera.Bounds.Size);

                for (int y = start.Y; y <= end.Y; y++)
                {
                    for (int x = start.X; x <= end.X; x++)
                    {
                        var realIndex = Utils.DimensionIndex(x, y, layer.CellCount.X);
                        if (realIndex >= layer.Data.Length)
                        {
                            continue;
                        }
                        var dataTile = layer.Data[realIndex];
                        if (dataTile == -1)
                        {
                            continue;
                        }

                        var worldIndex = Utils.DimensionIndex(realIndex, layer.CellCount.X);

                        dst.X = (int)Entity.Position.X + (int)LocalOffset.X + worldIndex.X * layer.CellSize.X;
                        dst.Y = (int)Entity.Position.Y + (int)LocalOffset.Y + worldIndex.Y * layer.CellSize.Y;

                        var src = tile.TileSources[dataTile];

                        batcher.Draw(tile.LoadedTexture, dst, src, Color, SpriteEffects.None);
#if DEBUG
                        Tilerenders++;
#endif
                    }
                }
            }
        }
Exemple #14
0
        public override void Render(Batcher batcher, Camera camera)
        {
            if (Texture == null)
            {
                return;
            }

            batcher.Draw(Texture, Bounds);
            foreach (var tracker in _trackers)
            {
                var position = tracker.PositionGetter();
                batcher.DrawRect(
                    _bounds.Location.X + position.X / Tile.Width - 1,
                    _bounds.Location.Y + position.Y / Tile.Height - 1,
                    2,
                    2,
                    tracker.DotColor);
            }
        }
Exemple #15
0
        public void DrawInto(Batcher batcher, ref FontCharacterSource text, Vector2 position, Color color,
                             float rotation, Vector2 origin, Vector2 scale, SpriteEffects effect, float depth)
        {
            var flipAdjustment = Vector2.Zero;

            var flippedVert = (effect & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically;
            var flippedHorz = (effect & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally;

            if (flippedVert || flippedHorz)
            {
                var size = MeasureString(ref text);

                if (flippedHorz)
                {
                    origin.X        *= -1;
                    flipAdjustment.X = -size.X;
                }

                if (flippedVert)
                {
                    origin.Y        *= -1;
                    flipAdjustment.Y = LineHeight - size.Y;
                }
            }


            var requiresTransformation = flippedHorz || flippedVert || rotation != 0f || scale != new Vector2(1);

            if (requiresTransformation)
            {
                Matrix2D temp;
                Matrix2D.CreateTranslation(-origin.X, -origin.Y, out _transformationMatrix);
                Matrix2D.CreateScale((flippedHorz ? -scale.X : scale.X), (flippedVert ? -scale.Y : scale.Y), out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
                Matrix2D.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, out temp);
                Matrix2D.Multiply(ref temp, ref _transformationMatrix, out _transformationMatrix);
                Matrix2D.CreateRotation(rotation, out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
                Matrix2D.CreateTranslation(position.X, position.Y, out temp);
                Matrix2D.Multiply(ref _transformationMatrix, ref temp, out _transformationMatrix);
            }

            var       previousCharacter = ' ';
            Character currentChar       = null;
            var       offset            = requiresTransformation ? Vector2.Zero : position - origin;

            for (var i = 0; i < text.Length; ++i)
            {
                var c = text[i];
                if (c == '\r')
                {
                    continue;
                }

                if (c == '\n')
                {
                    offset.X    = requiresTransformation ? 0f : position.X - origin.X;
                    offset.Y   += LineHeight;
                    currentChar = null;
                    continue;
                }

                if (currentChar != null)
                {
                    offset.X += Spacing.X + currentChar.XAdvance;
                }

                currentChar = ContainsCharacter(c) ? this[c] : DefaultCharacter;

                var p = offset;

                if (flippedHorz)
                {
                    p.X += currentChar.Bounds.Width;
                }
                p.X += currentChar.Offset.X + GetKerning(previousCharacter, currentChar.Char);

                if (flippedVert)
                {
                    p.Y += currentChar.Bounds.Height - LineHeight;
                }
                p.Y += currentChar.Offset.Y;

                // transform our point if we need to
                if (requiresTransformation)
                {
                    Vector2Ext.Transform(ref p, ref _transformationMatrix, out p);
                }

                var destRect = RectangleExt.FromFloats
                               (
                    p.X, p.Y,
                    currentChar.Bounds.Width * scale.X,
                    currentChar.Bounds.Height * scale.Y
                               );

                batcher.Draw(Textures[currentChar.TexturePage], destRect, currentChar.Bounds, color, rotation, Vector2.Zero, effect, depth);
                previousCharacter = c;
            }
        }
Exemple #16
0
        public void DrawTile(Batcher batcher, Vector2 position, float layerDepth, int x, int y, float scale)
        {
            var tile = GetTile(x, y);

            if (tile == null)
            {
                return;
            }

            var t          = TiledMap.IsometricTileToWorldPosition(x, y);
            var tileRegion = tile.TextureRegion;

            // for the y position, we need to take into account if the tile is larger than the tileHeight and shift. Tiled uses
            // a bottom-left coordinate system and MonoGame a top-left
            var rotation = 0f;

            var spriteEffects = SpriteEffects.None;

            if (tile.FlippedHorizonally)
            {
                spriteEffects |= SpriteEffects.FlipHorizontally;
            }
            if (tile.FlippedVertically)
            {
                spriteEffects |= SpriteEffects.FlipVertically;
            }
            if (tile.FlippedDiagonally)
            {
                if (tile.FlippedHorizonally && tile.FlippedVertically)
                {
                    spriteEffects ^= SpriteEffects.FlipVertically;
                    rotation       = MathHelper.PiOver2;
                    t.X           += TiledMap.TileHeight + (tileRegion.SourceRect.Height - TiledMap.TileHeight);
                    t.Y           -= (tileRegion.SourceRect.Width - TiledMap.TileWidth);
                }
                else if (tile.FlippedHorizonally)
                {
                    spriteEffects ^= SpriteEffects.FlipVertically;
                    rotation       = -MathHelper.PiOver2;
                    t.Y           += TiledMap.TileHeight;
                }
                else if (tile.FlippedVertically)
                {
                    spriteEffects ^= SpriteEffects.FlipHorizontally;
                    rotation       = MathHelper.PiOver2;
                    t.X           += TiledMap.TileWidth + (tileRegion.SourceRect.Height - TiledMap.TileHeight);
                    t.Y           += (TiledMap.TileWidth - tileRegion.SourceRect.Width);
                }
                else
                {
                    spriteEffects ^= SpriteEffects.FlipHorizontally;
                    rotation       = -MathHelper.PiOver2;
                    t.Y           += TiledMap.TileHeight;
                }
            }

            // if we had no rotations (diagonal flipping) shift our y-coord to account for any non-tileSized tiles to account for
            // Tiled being bottom-left origin
            if (rotation == 0)
            {
                t.Y += (TiledMap.TileHeight - tileRegion.SourceRect.Height);
            }

            // Scale the tile's relative position, but not the origin
            t = t * new Vector2(scale) + position;

            batcher.Draw(tileRegion.Texture2D, t, tileRegion.SourceRect, Color, rotation, Vector2.Zero, scale, spriteEffects, layerDepth);
        }
Exemple #17
0
 public override void Render(Batcher batcher, Camera camera)
 {
     batcher.Draw(Sprite, Transform.Position, Sprite.SourceRect, Color, Transform.Rotation,
                  Sprite.Center, Transform.Scale, SpriteEffects.None, _layerDepth);
 }
Exemple #18
0
 public void Render(Batcher batcher, Camera camera)
 {
     batcher.Draw(_sprite, Position, _renderColor, _rotation, _origin, _scale, _spriteEffects,
                  _layerDepth);
 }
Exemple #19
0
        public override void Draw(Batcher batcher, float x, float y, float width, float height, Color color)
        {
            float regionWidth = Sprite.SourceRect.Width * ScaleX, regionHeight = Sprite.SourceRect.Height * ScaleY;
            int   fullX = (int)(width / regionWidth), fullY = (int)(height / regionHeight);
            float remainingSourceX = (width - regionWidth * fullX) / ScaleX, remainingSourceY = (height - regionHeight * fullY) / ScaleY;
            float startX = x, startY = y;

            // draw all full, unclipped first
            for (var i = 0; i < fullX; i++)
            {
                y = startY;
                for (var j = 0; j < fullY; j++)
                {
                    batcher.Draw(Sprite, new Rectangle((int)x, (int)y,
                                                       (int)regionWidth, (int)regionHeight),
                                 Sprite.SourceRect, color);
                    y += regionHeight;
                }

                x += regionWidth;
            }

            var tempSourceRect = Sprite.SourceRect;

            if (remainingSourceX > 0)
            {
                // right edge

                tempSourceRect.Width = (int)remainingSourceX + 1;
                y = startY;
                for (var ii = 0; ii < fullY; ii++)
                {
                    batcher.Draw(Sprite, new Rectangle((int)x, (int)y,
                                                       (int)(tempSourceRect.Width * ScaleX), (int)regionHeight),
                                 tempSourceRect, color);
                    y += regionHeight;
                }

                // lower right corner.
                tempSourceRect.Height = (int)remainingSourceY + 1;
                if (remainingSourceY > 0)
                {
                    batcher.Draw(Sprite, new Rectangle((int)x, (int)y,
                                                       (int)(tempSourceRect.Width * ScaleX), (int)(tempSourceRect.Height * ScaleY)),
                                 tempSourceRect, color);
                }
            }

            if (remainingSourceY > 0)
            {
                // bottom edge
                tempSourceRect.Height = (int)remainingSourceY + 1;
                tempSourceRect.Width  = Sprite.SourceRect.Width;
                x = startX;
                for (var i = 0; i < fullX; i++)
                {
                    batcher.Draw(Sprite, new Rectangle((int)x, (int)y,
                                                       (int)regionWidth, (int)(tempSourceRect.Height * ScaleY)),
                                 tempSourceRect, color);
                    x += regionWidth;
                }
            }
        }
Exemple #20
0
        public override void Draw(Batcher batcher, Vector2 position, Vector2 scale, float layerDepth,
                                  RectangleF cameraClipBounds)
        {
            // offset it by the entity position since the tilemap will always expect positions in its own coordinate space
            cameraClipBounds.Location -= (position + Offset);

            int minX, minY, maxX, maxY;

            if (TiledMap.requiresLargeTileCulling)
            {
                // we expand our cameraClipBounds by the excess tile width/height of the largest tiles to ensure we include tiles whose
                // origin might be outside of the cameraClipBounds
                minX = TiledMap.WorldToTilePositionX((cameraClipBounds.Left -
                                                      (TiledMap.LargestTileWidth - TiledMap.TileWidth)) / scale.X);
                minY = TiledMap.WorldToTilePositionY((cameraClipBounds.Top -
                                                      (TiledMap.LargestTileHeight - TiledMap.TileHeight)) / scale.Y);
                maxX = TiledMap.WorldToTilePositionX((cameraClipBounds.Right +
                                                      (TiledMap.LargestTileWidth - TiledMap.TileWidth)) / scale.X);
                maxY = TiledMap.WorldToTilePositionY((cameraClipBounds.Bottom +
                                                      (TiledMap.LargestTileHeight - TiledMap.TileHeight)) / scale.Y);
            }
            else
            {
                minX = Mathf.Clamp(TiledMap.WorldToTilePositionX(cameraClipBounds.Left / scale.X), 0, TiledMap.Width - 1);
                minY = Mathf.Clamp(TiledMap.WorldToTilePositionX(cameraClipBounds.Top / scale.Y), 0, TiledMap.Height - 1);
                maxX = Mathf.Clamp(TiledMap.WorldToTilePositionX(cameraClipBounds.Right / scale.X), 0, TiledMap.Width - 1);
                maxY = Mathf.Clamp(TiledMap.WorldToTilePositionX(cameraClipBounds.Bottom / scale.Y), 0, TiledMap.Height - 1);
            }

            // loop through and draw all the non-culled tiles
            for (var y = minY; y <= maxY; y++)
            {
                for (var x = minX; x <= maxX; x++)
                {
                    var tile = GetTile(x, y);
                    if (tile == null)
                    {
                        continue;
                    }

                    var tileRegion = tile.TextureRegion;

                    // culling for arbitrary size tiles if necessary
                    if (TiledMap.requiresLargeTileCulling)
                    {
                        // TODO: this only checks left and bottom. we should check top and right as well to deal with rotated, odd-sized tiles
                        var tileworldpos = TiledMap.TileToWorldPosition(new Point(x, y));
                        if (tileworldpos.X + tileRegion.SourceRect.Width < cameraClipBounds.Left ||
                            tileworldpos.Y - tileRegion.SourceRect.Height > cameraClipBounds.Bottom)
                        {
                            continue;
                        }
                    }

                    // for the y position, we need to take into account if the tile is larger than the tileHeight and shift. Tiled uses
                    // a bottom-left coordinate system and MonoGame a top-left
                    var tx       = tile.X * TiledMap.TileWidth * scale.X + (int)position.X;
                    var ty       = tile.Y * TiledMap.TileHeight * scale.Y + (int)position.Y;
                    var rotation = 0f;

                    var spriteEffects = SpriteEffects.None;
                    if (tile.FlippedHorizonally)
                    {
                        spriteEffects |= SpriteEffects.FlipHorizontally;
                    }
                    if (tile.FlippedVertically)
                    {
                        spriteEffects |= SpriteEffects.FlipVertically;
                    }
                    if (tile.FlippedDiagonally)
                    {
                        if (tile.FlippedHorizonally && tile.FlippedVertically)
                        {
                            spriteEffects ^= SpriteEffects.FlipVertically;
                            rotation       = MathHelper.PiOver2;
                            tx            += TiledMap.TileHeight + (tileRegion.SourceRect.Height - TiledMap.TileHeight);
                            ty            -= (tileRegion.SourceRect.Width - TiledMap.TileWidth);
                        }
                        else if (tile.FlippedHorizonally)
                        {
                            spriteEffects ^= SpriteEffects.FlipVertically;
                            rotation       = -MathHelper.PiOver2;
                            ty            += TiledMap.TileHeight;
                        }
                        else if (tile.FlippedVertically)
                        {
                            spriteEffects ^= SpriteEffects.FlipHorizontally;
                            rotation       = MathHelper.PiOver2;
                            tx            += TiledMap.TileWidth + (tileRegion.SourceRect.Height - TiledMap.TileHeight);
                            ty            += (TiledMap.TileWidth - tileRegion.SourceRect.Width);
                        }
                        else
                        {
                            spriteEffects ^= SpriteEffects.FlipHorizontally;
                            rotation       = -MathHelper.PiOver2;
                            ty            += TiledMap.TileHeight;
                        }
                    }

                    // if we had no rotations (diagonal flipping) shift our y-coord to account for any non-tileSized tiles to account for
                    // Tiled being bottom-left origin
                    if (rotation == 0)
                    {
                        ty += (TiledMap.TileHeight - tileRegion.SourceRect.Height);
                    }

                    batcher.Draw(tileRegion, new Vector2(tx, ty) + Offset, Color, rotation, Vector2.Zero, scale,
                                 spriteEffects, layerDepth);
                }
            }
        }
Exemple #21
0
 public override void Draw(Batcher batcher, Vector2 position, Vector2 scale, float layerDepth, RectangleF cameraClipBounds)
 {
     batcher.Draw(Texture, position + Offset, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, layerDepth);
 }
Exemple #22
0
 public void Draw(Batcher batcher)
 {
     batcher.Draw(Texture, Offset, Color.White);
 }
Exemple #23
0
 public override void Render(Batcher batcher, Camera camera)
 {
     batcher.Draw(_spriteToMime.Sprite, Entity.Transform.Position + _localOffset, Color,
                  Entity.Transform.Rotation, _spriteToMime.Origin, Entity.Transform.Scale, _spriteToMime.SpriteEffects,
                  _layerDepth);
 }