本文整理汇总了C++中tmx::Map::GetErrorCode方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetErrorCode方法的具体用法?C++ Map::GetErrorCode怎么用?C++ Map::GetErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmx::Map
的用法示例。
在下文中一共展示了Map::GetErrorCode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: topleft
Room*
RoomLoader::LoadRoom( const std::string& aRoomName )
{
Tmx::Map map;
map.ParseFile(aRoomName);
if (map.HasError()) {
printf("error code: %d\n", map.GetErrorCode());
printf("error text: %s\n", map.GetErrorText().c_str());
return NULL;
}
Room* room = new Room(GetLayer(map, "background"), GetLayer(map, "middle"), GetLayer(map, "foreground"));
std::vector<Entity*> entities = GetEntities(map, "entities");
float2 topleft(0,0);
float2 bottomright((map.GetWidth()) * map.GetTileWidth(), (map.GetHeight()) * map.GetTileHeight());
std::vector<std::pair<float2, float2>> rects = GetCameraRects(map, "camera");
room->setCameraRect(topleft, bottomright);
room->setCamera(new Camera(rects));
for (unsigned int i = 0; i < entities.size(); i++)
{
room->addEntity(entities[i]);
}
return room;
}
示例2: LoadFromFile
bool TmxHandler::LoadFromFile(const GQE::typeAssetID theAssetID, Tmx::Map& theMap)
{
// Start with a return result of false
bool anResult = false;
// Retrieve the filename for this asset
std::string anFilename = GetFilename(theAssetID);
// Was a valid filename found? then attempt to load the asset from anFilename
if(anFilename.length() > 0)
{
theMap.ParseFile(anFilename);
if(!theMap.HasError())
{
anResult=true;
}
else
{
ILOG() << "Error Loading Tmx File. Error Code: "<<theMap.GetErrorCode()<<std::endl;
}
}
else
{
ELOG() << "TmxHandler::LoadFromFile(" << theAssetID
<< ") No filename provided!" << std::endl;
}
// Return anResult of true if successful, false otherwise
return anResult;
}
示例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
int main(int argc, char * argv[])
{
Tmx::Map *map = new Tmx::Map();
std::string fileName = (argc > 1) ? argv[1] : "./example/example.tmx";
map->ParseFile(fileName);
if (map->HasError())
{
printf("error code: %d\n", map->GetErrorCode());
printf("error text: %s\n", map->GetErrorText().c_str());
return map->GetErrorCode();
}
printf("====================================\n");
printf("Map\n");
printf("====================================\n");
printf("Version: %1.1f\n", map->GetVersion());
printf("Orientation: %d\n", map->GetOrientation());
if (!map->GetBackgroundColor().IsTransparent())
printf("Background Color (hex): %s\n",
map->GetBackgroundColor().ToString().c_str());
printf("Render Order: %d\n", map->GetRenderOrder());
if (map->GetStaggerAxis())
printf("Stagger Axis: %d\n", map->GetStaggerAxis());
if (map->GetStaggerIndex())
printf("Stagger Index: %d\n", map->GetStaggerIndex());
printf("Width: %d\n", map->GetWidth());
printf("Height: %d\n", map->GetHeight());
printf("Tile Width: %d\n", map->GetTileWidth());
printf("Tile Height: %d\n", map->GetTileHeight());
// Iterate through map properties and print the type, name and value of each property.
const std::unordered_map<std::string, Tmx::Property> &mapProperties = map->GetProperties().GetPropertyMap();
for (auto &pair : mapProperties)
{
const Tmx::Property &property = pair.second;
std::string type;
if (property.GetType() == Tmx::TMX_PROPERTY_STRING)
{
type = "String";
}
else if (property.GetType() == Tmx::TMX_PROPERTY_FLOAT)
{
type = "Float";
}
else if (property.GetType() == Tmx::TMX_PROPERTY_INT)
{
type = "Integer";
}
else if (property.GetType() == Tmx::TMX_PROPERTY_BOOL)
{
type = "Boolean";
}
else if (property.GetType() == Tmx::TMX_PROPERTY_COLOR)
{
type = "Color";
}
else if (property.GetType() == Tmx::TMX_PROPERTY_FILE)
{
type = "File";
}
else
{
type = "Unknown";
}
printf("Map property %s (%s) = %s\n", pair.first.c_str(), type.c_str(), property.GetValue().c_str());
}
// Make sure property parsing works correctly across the library.
assert(mapProperties.at("StringProperty").GetValue() == map->GetProperties().GetStringProperty("StringProperty"));
assert(mapProperties.at("IntProperty").GetIntValue() == map->GetProperties().GetIntProperty("IntProperty"));
assert(mapProperties.at("NegativeIntProperty").GetIntValue() == map->GetProperties().GetIntProperty("NegativeIntProperty"));
assert(mapProperties.at("FloatProperty").GetFloatValue() == map->GetProperties().GetFloatProperty("FloatProperty"));
assert(mapProperties.at("NegativeFloatProperty").GetFloatValue() == map->GetProperties().GetFloatProperty("NegativeFloatProperty"));
assert(mapProperties.at("BigInteger").GetIntValue() == map->GetProperties().GetIntProperty("BigInteger"));
assert(mapProperties.at("FalseProperty").GetBoolValue() == map->GetProperties().GetBoolProperty("FalseProperty"));
assert(mapProperties.at("TrueProperty").GetBoolValue() == map->GetProperties().GetBoolProperty("TrueProperty"));
assert(mapProperties.at("YellowProperty").GetColorValue() == map->GetProperties().GetColorProperty("YellowProperty"));
assert(mapProperties.at("FileProperty").GetBoolValue() == map->GetProperties().GetBoolProperty("FileProperty"));
// Make sure color can be converted from and to string
assert(map->GetProperties().GetColorProperty("YellowProperty").ToString() == map->GetProperties().GetStringProperty("YellowProperty"));
assert(Tmx::Color("#ffffff") == Tmx::Color("#ffffffff"));
// Iterate through the tilesets.
for (int i = 0; i < map->GetNumTilesets(); ++i)
{
printf(" \n");
printf("====================================\n");
printf("Tileset : %02d\n", i);
printf("====================================\n");
// Get a tileset.
const Tmx::Tileset *tileset = map->GetTileset(i);
//.........这里部分代码省略.........
示例5: main
int main(int argc, char * argv[])
{
Tmx::Map *map = new Tmx::Map();
//std::string fileName = (argc > 1) ? argv[1] : "./example/example.tmx";
std::string fileName = (argc > 1) ? argv[1] : "1.tmx";
map->ParseFile(fileName);
if (map->HasError())
{
printf("error code: %d\n", map->GetErrorCode());
printf("error text: %s\n", map->GetErrorText().c_str());
return map->GetErrorCode();
}
printf("====================================\n");
printf("Map\n");
printf("====================================\n");
printf("Version: %1.1f\n", map->GetVersion());
printf("Orientation: %d\n", map->GetOrientation());
if (!map->GetBackgroundColor().empty())
printf("Background Color (hex): %s\n",
map->GetBackgroundColor().c_str());
printf("Render Order: %d\n", map->GetRenderOrder());
if (map->GetStaggerAxis())
printf("Stagger Axis: %d\n", map->GetStaggerAxis());
if (map->GetStaggerIndex())
printf("Stagger Index: %d\n", map->GetStaggerIndex());
printf("Width: %d\n", map->GetWidth());
printf("Height: %d\n", map->GetHeight());
printf("Tile Width: %d\n", map->GetTileWidth());
printf("Tile Height: %d\n", map->GetTileHeight());
// Iterate through the tilesets.
for (int i = 0; i < map->GetNumTilesets(); ++i)
{
printf(" \n");
printf("====================================\n");
printf("Tileset : %02d\n", i);
printf("====================================\n");
// Get a tileset.
const Tmx::Tileset *tileset = map->GetTileset(i);
// Print tileset information.
printf("Name: %s\n", tileset->GetName().c_str());
printf("Margin: %d\n", tileset->GetMargin());
printf("Spacing: %d\n", tileset->GetSpacing());
printf("First gid: %d\n", tileset->GetFirstGid());
printf("Image Width: %d\n", tileset->GetImage()->GetWidth());
printf("Image Height: %d\n", tileset->GetImage()->GetHeight());
printf("Image Source: %s\n", tileset->GetImage()->GetSource().c_str());
if (!tileset->GetImage()->GetTransparentColor().empty())
printf("Transparent Color (hex): %s\n",
tileset->GetImage()->GetTransparentColor().c_str());
if (tileset->GetTiles().size() > 0)
{
// Get a tile from the tileset.
const Tmx::Tile *tile = *(tileset->GetTiles().begin());
// Print the properties of a tile.
std::map<std::string, std::string> list =
tile->GetProperties().GetList();
std::map<std::string, std::string>::iterator iter;
for (iter = list.begin(); iter != list.end(); ++iter)
{
printf("%s = %s\n", iter->first.c_str(), iter->second.c_str());
}
if (tile->IsAnimated())
{
printf(
"Tile is animated: %d frames with total duration of %dms.\n",
tile->GetFrameCount(), tile->GetTotalDuration());
const std::vector<Tmx::AnimationFrame> &frames =
tile->GetFrames();
int i = 0;
for (std::vector<Tmx::AnimationFrame>::const_iterator it =
frames.begin(); it != frames.end(); it++, i++)
{
printf("\tFrame %d: Tile ID = %d, Duration = %dms\n", i,
it->GetTileID(), it->GetDuration());
}
}
if (tile->HasObjects())
{
printf(
"Tile has objects.\n");
// Iterate through all Collision objects in the tile.
for (int j = 0; j < tile->GetNumObjects(); ++j)
{
// Get an object.
const Tmx::Object *object = tile->GetObject(j);
//.........这里部分代码省略.........
示例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;
//.........这里部分代码省略.........