Пример #1
0
        void LoadTileLayer(int index)
        {
            if (map.Layers.Length <= index)
            {
                return;
            }
            uint[,] tiles = map.Layers[index].GetTileArrayRaw();
            for (int c = 0; c < tiles.GetLength(0); c++)
            {
                for (int r = 0; r < tiles.GetLength(1); r++)
                {
                    if (tiles[c, r] == 0)
                    {
                        continue;
                    }
                    uint    rawTileInfo = tiles[c, r];
                    int     frame       = TiledUtils.GetTileFrame(rawTileInfo);
                    TileSet tileSet     = map.GetTileSet(frame);
                    if (tileSet == null || tileSet.Image == null)
                    {
                        throw new Exception("The Tiled map contains unembedded tilesets (.tsx files) - please embed them in the map");
                    }

                    AnimationSprite Tile = new AnimationSprite(
                        Path.Combine(_foldername, tileSet.Image.FileName),
                        tileSet.Columns, tileSet.Rows,
                        -1, false, addColliders
                        );
                    Tile.SetFrame(frame - tileSet.FirstGId);
                    Tile.x = c * map.TileWidth;
                    // Adapting to Tiled's weird and inconsistent conventions again:
                    Tile.y = r * map.TileHeight - (Tile.height - map.TileHeight);
                    ChangeOrigin(Tile, 0.5f, 0.5f);
                    Tile.rotation = TiledUtils.GetRotation(rawTileInfo);
                    Tile.Mirror(TiledUtils.GetMirrorX(rawTileInfo), false);
                    ChangeOrigin(Tile, defaultOriginX, defaultOriginY, 0.5f, 0.5f);

                    rootObject.AddChild(Tile);
                }
            }
        }
Пример #2
0
        void FillTileArray(short[,] sgrid = null, uint[,] uigrid = null)
        {
            string[] lines = Data.innerXML.Split('\n');
            int      row   = 0;

            foreach (string line in lines)
            {
                if (line.Length <= 1)
                {
                    continue;
                }
                string parseLine = line;
                if (line [line.Length - 1] == ',')
                {
                    parseLine = line.Substring(0, line.Length - 1);
                }

                string[] chars = parseLine.Split(',');
                for (int col = 0; col < chars.Length; col++)
                {
                    if (col < Width)
                    {
                        uint tileNum = uint.Parse(chars[col]);
                        if (uigrid != null)
                        {
                            uigrid[col, row] = tileNum;
                        }
                        if (sgrid != null)
                        {
                            sgrid[col, row] = (short)TiledUtils.GetTileFrame(tileNum);
                        }
                    }
                }
                row++;
            }
        }