Exemplo n.º 1
0
Arquivo: Map.cs Projeto: hnjm/tilemap
    public void SetVisibleRegion(float x, float y, float w, float h)
    {
        visibleTiles.Clear();

        //normalize the parameters.
        float left  = x / MapUtil.TILE_LENGTH;
        float lower = y / MapUtil.TILE_LENGTH;
        float right = w / MapUtil.TILE_LENGTH;
        float upper = h / MapUtil.TILE_LENGTH;

        //get all visible tiles inside the rigion
        ICollection <Vec2> points = loadingStrategy.GetTilesToLoad(left, lower, right, upper, size.x, size.y);

        foreach (var point in points)
        {
            //create the tile if not exist
            if (!tileSet.ContainsKey(point))
            {
                ITile    tile     = factory.CreateTile(point);
                TileView renderer = CreateTile(point);
                renderer.SetTile(tile);
                tileSet.Add(point, renderer);
                visibleTiles.Add(tile);
            }
            else
            {
                visibleTiles.Add(tileSet [point].GetTile());
            }
        }
    }
Exemplo n.º 2
0
    public List <ITile> Load(string fileName)
    {
        List <ITile> tileSet = new List <ITile> ();

        if (File.Exists(fileName))
        {
            FileStream stream = File.OpenRead(fileName);
            if (stream.CanRead)
            {
                BinaryFormatter formatter = new BinaryFormatter();

                List <Tile> tiles = formatter.Deserialize(stream) as List <Tile>;
                Debug.Log("Loaded tiles: " + tiles.Count);

                foreach (var t in tiles)
                {
                    ITile tile = factory.CreateTile(t.GetPoint());
                    tile.SetData(t.GetData());
                    tileSet.Add(tile);
                }
            }

            stream.Close();
        }

        return(tileSet);
    }