Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TiXmlElement* layerElement;
- layerElement = map->FirstChildElement("layer");
- while (layerElement)
- {
- Layer layer;
- if (layerElement->Attribute("opacity") != NULL)
- {
- float opacity = strtod(layerElement->Attribute("opacity"), NULL);
- layer.opacity = 255 * opacity;
- }
- else
- {
- layer.opacity = 255;
- }
- TiXmlElement* layerDataElement;
- layerDataElement = layerElement->FirstChildElement("data");
- if (layerDataElement == NULL)
- {
- std::cout << "Bad map. No layer information found." << std::endl;
- }
- string editTileMatrix = layerDataElement->GetText();
- for (int i = 0; i < editTileMatrix.size(); i++)
- {
- if (editTileMatrix[i] == ' ')
- {
- editTileMatrix[i] = ',';
- }
- }
- istringstream tileMatrix(editTileMatrix);
- string saveElementTileMatrix;
- while (getline(tileMatrix, saveElementTileMatrix, ','))
- {
- if(saveElementTileMatrix.size()!=0)
- matrix.push_back(stoi(saveElementTileMatrix));
- }
- string var = layerElement->Attribute("name");
- int x = 0;
- int y = 0;
- for (int i = 0; i < matrix.size(); i++)
- {
- int tileGID = matrix[i];
- int subRectToUse = tileGID - firstTileID;
- if (subRectToUse >= 0)
- {
- sf::Sprite sprite;
- sprite.setTexture(tilesetImage);
- sprite.setTextureRect(subRects[subRectToUse]);
- sprite.setPosition(x * tileWidth, y * tileHeight);
- sprite.setColor(sf::Color(255, 255, 255, layer.opacity));
- layer.tiles.push_back(sprite);
- cout << layer.tiles.size() << endl;
- }
- x++;
- if (x >= width)
- {
- x = 0;
- y++;
- if (y >= height)
- y = 0;
- }
- }
- if (var == "Tree")
- objects = layer.tiles;
- layers.push_back(layer);
- layerElement = layerElement->NextSiblingElement("layer");
- }
Advertisement
Add Comment
Please, Sign In to add comment