void TileMap::drawlayer(Layer * layer) { //for(std::map<std::string, Layer*>::iterator it = _layers.begin(); it!=_layers.end(); it++) //{ // Layer* layer = it->second; std::pair<int, int> p = layer->firstGid(); while(p.second != 0) { Tileset * set = findTilesetByGid(p.second); if(set) { set->copy(_image.surface(), ((p.first)%_w)*_tileWidth, ((p.first)/_w)*_tileHeight, p.second); } p = layer->nextGid(); } //} _image.update(); }
bool TileMap::setGid(int x, int y, int gid) { if(_layers.size() <= 0) return false; SDL_Rect rect; rect.x = x/_tileWidth * _tileWidth; rect.y = y/_tileHeight* _tileHeight; rect.w = _tileWidth; rect.h = _tileHeight; _image.fill(&_bgColor, &rect); int position = x/_tileWidth + y/_tileHeight*_w; Layer* layer = _layers.begin()->second; layer->setGid(position, gid); Tileset * tileset = findTilesetByGid(gid); if(tileset && gid != 0) tileset->copy(_image.surface(), rect.x, rect.y, gid); return true; }