本文整理汇总了C++中tmx::Map::GetNumTileLayers方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetNumTileLayers方法的具体用法?C++ Map::GetNumTileLayers怎么用?C++ Map::GetNumTileLayers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmx::Map
的用法示例。
在下文中一共展示了Map::GetNumTileLayers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
bool TileMap::load(const std::string& tmx_path) {
Tmx::Map map;
map.ParseFile(tmx_path);
if (map.HasError()) {
return false;
}
int width = map.GetWidth();
int height = map.GetHeight();
m_mapSize = sf::Vector2u(width, height);
m_tileSize = sf::Vector2u(map.GetTileWidth(), map.GetTileHeight());
std::string basepath = map.GetFilepath();
for (int i = 0; i < map.GetNumTilesets(); i++) {
const Tmx::Tileset *tileset = map.GetTileset(i);
m_tilesets.emplace_back();
if (!m_tilesets.back().load(*tileset, basepath))
return false;
}
for (int j = 0; j < map.GetNumTileLayers(); j++) {
const Tmx::TileLayer *tileLayer = map.GetTileLayer(j);
m_tilelayers.emplace_back();
if (!m_tilelayers.back().load(*tileLayer, m_tilesets, width, height))
return false;
}
return true;
}
示例2: parseTmx
void TileMap::parseTmx(Tmx::Map &tmxMap) {
this->width = tmxMap.GetWidth();
this->height = tmxMap.GetHeight();
this->tileWidth = tmxMap.GetTileWidth();
this->tileHeight = tmxMap.GetTileHeight();
LOG(INFO) << "Number of tilesets: " + std::to_string(tmxMap.GetNumTilesets());
std::vector<Tileset> tilesets;
for (int i = 0; i < tmxMap.GetNumTilesets(); ++i) {
const Tmx::Tileset *tmxTileset = tmxMap.GetTileset(i);
Tileset tileset;
tileset.imageSource = tmxTileset->GetImage()->GetSource();
tileset.imageWidth = tmxTileset->GetImage()->GetWidth();
tileset.imageHeight = tmxTileset->GetImage()->GetHeight();
tileset.tileWidth = tmxTileset->GetTileWidth();
tileset.tileHeight = tmxTileset->GetTileHeight();
tilesets.push_back(tileset);
}
for (int i = 0; i < tmxMap.GetNumTileLayers(); ++i) {
const Tmx::TileLayer *tmxTileLayer = tmxMap.GetTileLayer(i);
parseTileLayer(tilesets, tmxTileLayer);
}
}
示例3: LoadMap
void ParserMap::LoadMap(ServerMap *drawmap, const std::string &name)
{
// загрузка карты
Tmx::Map *map = new Tmx::Map();
map->ParseFile(Config::Get()["dir.maps"] + name);
if ( map->HasError() )
{
Log::Error("error code: " + std::to_string(map->GetErrorCode()));
Log::Error("error text: " + map->GetErrorText());
throw (std::runtime_error("map->GetErrorCode()"));
}
for ( int i = 0; i < map->GetNumTileLayers(); ++i )
{
const Tmx::TileLayer *tileLayer = map->GetTileLayer(i);
const std::string tileLayerName = tileLayer->GetName();
for ( int y = 0; y < tileLayer->GetHeight(); ++y )
{
for ( int x = 0; x < tileLayer->GetWidth(); ++x )
{
if ( tileLayer->GetTileTilesetIndex(x, y) == -1 )
{
}
else
{
if ( tileLayerName == "Collision" )
{
if ( tileLayer->GetTileGid(x, y) == 50 )
drawmap->m_tile[0][x][y].SetCollision(1);
}
else if ( tileLayerName == "enemy" )
{
if ( tileLayer->GetTileGid(x, y) == 52 )
drawmap->m_tile[0][x][y].SetEnemy(1);
}
else
{
drawmap->m_tile[i][x][y].SetTileId(tileLayer->GetTileGid(x, y) - 1);
}
}
}
}
}
delete map;
map = nullptr;
}
示例4: main
//.........这里部分代码省略.........
printf("Object Size: (%03d, %03d)\n", object->GetWidth(),
object->GetHeight());
// Print Polygon points.
const Tmx::Polygon *polygon = object->GetPolygon();
if (polygon != 0)
{
for (int i = 0; i < polygon->GetNumPoints(); i++)
{
const Tmx::Point &point = polygon->GetPoint(i);
printf("Object Polygon: Point %d: (%f, %f)\n", i, point.x,
point.y);
}
}
// Print Polyline points.
const Tmx::Polyline *polyline = object->GetPolyline();
if (polyline != 0)
{
for (int i = 0; i < polyline->GetNumPoints(); i++)
{
const Tmx::Point &point = polyline->GetPoint(i);
printf("Object Polyline: Point %d: (%f, %f)\n", i, point.x,
point.y);
}
}
}
}
}
}
// Iterate through the tile layers.
for (int i = 0; i < map->GetNumTileLayers(); ++i)
{
printf(" \n");
printf("====================================\n");
printf("Layer : %02d/%s \n", i, map->GetTileLayer(i)->GetName().c_str());
printf("====================================\n");
// Get a layer.
const Tmx::TileLayer *tileLayer = map->GetTileLayer(i);
for (int y = 0; y < tileLayer->GetHeight(); ++y)
{
for (int x = 0; x < tileLayer->GetWidth(); ++x)
{
if (tileLayer->GetTileTilesetIndex(x, y) == -1)
{
printf("........ ");
}
else
{
// Get the tile's id and gid.
printf("%03d(%03d)", tileLayer->GetTileId(x, y), tileLayer->GetTileGid(x, y));
// Find a tileset for that id.
//const Tmx::Tileset *tileset = map->FindTileset(layer->GetTileId(x, y));
if (tileLayer->IsTileFlippedHorizontally(x, y))
{
printf("h");
}
else
{
printf(" ");
}
示例5: main
//.........这里部分代码省略.........
printf("Object Size: (%03d, %03d)\n", object->GetWidth(),
object->GetHeight());
// Print Polygon points.
const Tmx::Polygon *polygon = object->GetPolygon();
if (polygon != 0)
{
for (int i = 0; i < polygon->GetNumPoints(); i++)
{
const Tmx::Point &point = polygon->GetPoint(i);
printf("Object Polygon: Point %d: (%f, %f)\n", i, point.x,
point.y);
}
}
// Print Polyline points.
const Tmx::Polyline *polyline = object->GetPolyline();
if (polyline != 0)
{
for (int i = 0; i < polyline->GetNumPoints(); i++)
{
const Tmx::Point &point = polyline->GetPoint(i);
printf("Object Polyline: Point %d: (%f, %f)\n", i, point.x,
point.y);
}
}
}
}
}
}
// Iterate through the tile layers.
for (int i = 0; i < map->GetNumTileLayers(); ++i)
{
printf(" \n");
printf("====================================\n");
printf("Layer : %02d/%s \n", i, map->GetTileLayer(i)->GetName().c_str());
printf("====================================\n");
// Get a layer.
const Tmx::TileLayer *tileLayer = map->GetTileLayer(i);
for (int y = 0; y < tileLayer->GetHeight(); ++y)
{
for (int x = 0; x < tileLayer->GetWidth(); ++x)
{
if (tileLayer->GetTileTilesetIndex(x, y) == -1)
{
printf("........ ");
}
else
{
// Get the tile's id and gid.
printf("%03d(%03d)", tileLayer->GetTileId(x, y), tileLayer->GetTileGid(x, y));
// Find a tileset for that id.
//const Tmx::Tileset *tileset = map->FindTileset(layer->GetTileId(x, y));
if (tileLayer->IsTileFlippedHorizontally(x, y))
{
printf("h");
}
else
{
printf(" ");
}
示例6: 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;
//.........这里部分代码省略.........