示例#1
0
        private static void Render(
            Tiles.Visible tile,
            int tileIndex, // Tile index in its layer
            Map map,
            ContentManager contentManager,
            SpriteBatch spriteBatch,
            Camera camera
            )
        {
            if (tile.gid == 0)
            {
                // Skip empty tiles
                return;
            }

            PhysicalVector2 tilePos  = GetTilePosition(map, tileIndex);
            var             position = new Ecs.Components.Position()
            {
                data = tilePos
            };

            Tileset   tileset             = GetTilesetOfTile(map, tile.gid);
            Texture2D tilesetTexture      = GetTexture(contentManager, tileset);
            var       texturePosRectangle = GetTexturePosRectangle(
                tile.gid,
                tileset,
                map
                );
            var           destRectangle = GetDestRectangle(map);
            SpriteEffects effects       = GetSpriteEffects(tile);

            var sprite = new EcsExt.Components.Visibles.Sprite()
            {
                texture             = tilesetTexture,
                texturePosRectangle = texturePosRectangle,
                destRectangle       = destRectangle,
                tint    = Color.White,
                effects = effects
            };

            EcsExt.Systems.SpriteRender.Render(
                sprite,
                position,
                spriteBatch,
                camera
                );
        }
示例#2
0
        // Get information on flipping the tile
        public static SpriteEffects GetSpriteEffects(
            Tiles.Visible tile
            )
        {
            if (!tile.horizontalFlip &&
                !tile.verticalFlip &&
                !tile.diagonalFlip
                )
            {
                return(SpriteEffects.None);
            }

            if (tile.horizontalFlip &&
                !tile.verticalFlip &&
                !tile.diagonalFlip
                )
            {
                return(SpriteEffects.FlipHorizontally);
            }

            if (!tile.horizontalFlip &&
                tile.verticalFlip &&
                !tile.diagonalFlip
                )
            {
                return(SpriteEffects.FlipVertically);
            }

            if (tile.horizontalFlip &&
                tile.verticalFlip &&
                !tile.diagonalFlip
                )
            {
                return(SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically);
            }

            if (tile.horizontalFlip &&
                !tile.verticalFlip &&
                tile.diagonalFlip
                )
            {
                // TODO: Rotate 90 deg clockwise
                Console.WriteLine("[WARN] Unsupported tile rotation (90 deg)");
                return(SpriteEffects.None);
            }

            if (!tile.horizontalFlip &&
                tile.verticalFlip &&
                tile.diagonalFlip
                )
            {
                // TODO: Rotate 270 deg clockwise
                Console.WriteLine("[WARN] Unsupported tile rotation (270 deg)");
                return(SpriteEffects.None);
            }

            Console.WriteLine("[WARN] Unknown tile transform");
            Console.WriteLine("[WARN] HFlip: {0}", tile.horizontalFlip);
            Console.WriteLine("[WARN] VFlip: {0}", tile.verticalFlip);
            Console.WriteLine("[WARN] DFlip: {0}", tile.diagonalFlip);
            return(SpriteEffects.None);
        }