本文整理汇总了C++中tmx::Map::GetFilename方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetFilename方法的具体用法?C++ Map::GetFilename怎么用?C++ Map::GetFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmx::Map
的用法示例。
在下文中一共展示了Map::GetFilename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
std::unique_ptr<Map> MapLoader::Load(const std::string& path)
{
Tmx::Map* map = new Tmx::Map();
map->ParseFile(RESOURCE_FOLDER + path);
auto ThrowError = [&]() {
Logger::Log("Unable to load map: \"" + path + "\"", licesium::Logger::Error);
throw map->GetErrorCode();
};
if (map->HasError() || map->GetOrientation() != Tmx::TMX_MO_ISOMETRIC)
{
ThrowError();
}
auto resultMap = std::unique_ptr<Map>(new Map(map->GetFilename()));
size_t tileWidth = static_cast<size_t>(map->GetTileWidth());
size_t tileHeight = static_cast<size_t>(map->GetTileHeight());
float tileRatio = static_cast<float>(tileWidth) / static_cast<float>(tileHeight);
resultMap->m_mapSize = sf::Vector2u(map->GetWidth(), map->GetHeight());
resultMap->m_tileSize = sf::Vector2u(tileWidth, tileHeight);
resultMap->m_tileRatio = tileRatio;
resultMap->m_renderOrder = map->GetRenderOrder();
for (int i = 0; i < map->GetNumTilesets(); ++i)
{
const Tmx::Tileset* tileset = map->GetTileset(i);
std::unique_ptr<sf::Texture> tilesetTexture(new sf::Texture);
if (!tilesetTexture->loadFromFile(RESOURCE_FOLDER + tileset->GetImage()->GetSource()))
{
ThrowError();
}
int spacing = tileset->GetSpacing();
int margin = tileset->GetMargin();
int columns = (tilesetTexture->getSize().x - 2u * margin + spacing) / (tileWidth + spacing);
int rows = (tilesetTexture->getSize().y - 2u * margin + spacing) / (tileHeight + spacing);
for (int y = 0; y < rows; y++)
{
for (int x = 0; x < columns; x++)
{
sf::IntRect rect;
rect.top = y * (tileHeight + spacing);
rect.top += margin;
rect.height = tileHeight;
rect.left = x * (tileWidth + spacing);
rect.left += margin;
rect.width = tileWidth;
int id = resultMap->m_tileInfo.size();
resultMap->m_tileInfo.push_back(licesium::Map::TileInfo(rect,
sf::Vector2f(static_cast<float>(rect.width), static_cast<float>(rect.height)),
static_cast<sf::Uint16>(resultMap->m_tilesetTextures.size() - 1u)));
const Tmx::Tile* tile = tileset->GetTile(id);
if (tile->IsAnimated())
{
auto& resultTile = resultMap->m_tileInfo.back();
resultTile.animated = true;
resultTile.animationDuration = static_cast<float>(tile->GetTotalDuration());
const auto& frames = tile->GetFrames();
for (const auto& frame : frames)
{
resultTile.frames.push_back(std::make_pair(frame.GetTileID(), static_cast<float>(frame.GetDuration())));
}
}
}
}
resultMap->m_tilesetTextures.push_back(std::move(tilesetTexture));
}
for (int i = 0; i < map->GetNumTileLayers(); ++i)
{
const Tmx::TileLayer* tileLayer = map->GetTileLayer(i);
MapLayer mapLayer;
mapLayer.m_name = tileLayer->GetName();
mapLayer.m_opacity = tileLayer->GetOpacity();
mapLayer.m_visible = tileLayer->IsVisible();
for (int y = 0; y < tileLayer->GetHeight(); ++y)
{
for (int x = 0; x < tileLayer->GetWidth(); ++x)
{
if (tileLayer->GetTileTilesetIndex(x, y) != -1)
{
sf::Uint8 opacity = static_cast<sf::Uint8>(255.f * tileLayer->GetOpacity());
sf::Color color = sf::Color(255u, 255u, 255u, opacity);
sf::Vertex v0, v1, v2, v3;
//.........这里部分代码省略.........