Beispiel #1
0
int MapTileLayer::_tileRegion(const Coordinate& a, const Coordinate& b, int lod, bool async)
{
    MapLoader* loader = MapViewLayer::Context.Loader;
    auto ai = loader->getTileIndex(a, lod);
    auto bi = loader->getTileIndex(b, lod);
    Coordinate size = loader->getTileSize(lod);
    
    cocos2d::log("Map rebuild (%d,%d) (%d,%d)", ai.first, ai.second, bi.first, bi.second);
    int tilesNotYetLoaded = 0;
    for(int i = ai.second; i <= bi.second; ++i) // y axis
    {
        for(int j = ai.first; j <= bi.first; ++j) // x axis
        {
            Coordinate position = Coordinate(j*size.x, i*size.y);
            const MapTileInfo& tileInfo = loader->getMapTileInfo({j, i}, lod);
            tilesNotYetLoaded += addTile(tileInfo, position, size, async);
        }
    }
    return tilesNotYetLoaded;
}
Beispiel #2
0
void MapTileLayer::tileRegion(const Coordinate& a, const Coordinate& b, int lod)
{
    MapLoader* loader = MapViewLayer::Context.Loader;
    
    auto ai = loader->getTileIndex(a, lod);
    auto bi = loader->getTileIndex(b, lod);
    
    if(ai == m_indexA && bi == m_indexB && m_lod == lod){
        // don't rebuild map
        return;
    }
    removeAllChildren();
    m_indexA = ai;
    m_indexB = bi;
    m_lod = lod;
    
    int tilesPending = _tileRegion(a, b, lod, true);
    if(tilesPending > 0)
    {
        _tileRegion(a, b, lod+1, false);
    }
}