本文整理汇总了C++中tmx::Map::GetErrorText方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::GetErrorText方法的具体用法?C++ Map::GetErrorText怎么用?C++ Map::GetErrorText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tmx::Map
的用法示例。
在下文中一共展示了Map::GetErrorText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: load
const bool MapLoader::load( const std::string filename, MapLoader::callback tile_callback, MapLoader::callback object_callback ){
auto app = Application::getInstance();
Tmx::Map map;
map.ParseFile(filename);
if( map.HasError() ){
app->getRenderSystem().getDebugConsole()<<"\n"<<"Error Loading "<<filename<<": "<<map.GetErrorText();
return false;
}
// Load all of the tilesets
boost::unordered_map< std::string, phoenix::TexturePtr > tileset_textures;
for (int i = 0; i < map.GetNumTilesets(); ++i) {
const Tmx::Tileset *tileset = map.GetTileset(i);
auto t = app->getRenderSystem().loadTexture( tileset->GetImage()->GetSource() );
tileset_textures.insert( std::pair<std::string, phoenix::TexturePtr>( tileset->GetName(), t) );
app->getRenderSystem().getDebugConsole()<<"\n"<<"Loaded tileset texture "<<tileset->GetImage()->GetSource()<<" for "<<tileset->GetName();
}
// Go through each layer
for (int i = 0; i < map.GetNumLayers(); ++i) {
const Tmx::Layer *layer = map.GetLayer(i);
bea::TilemapPtr tiles = 0;
for (int x = 0; x < layer->GetWidth(); ++x) {
for (int y = 0; y < layer->GetHeight(); ++y) {
auto tile_id = layer->GetTileId(x, y);
if( tile_id == 0 ) continue;
const Tmx::Tileset *tileset = map.FindTileset(tile_id);
if( tileset == 0 ) continue;
// Create the tileset when we get to the first tile in the map
if( !tiles ){
tiles = new bea::Tilemap(
app->getObjectManager() ,
app->getRenderSystem().getBatchRenderer(),
layer->GetWidth(), layer->GetHeight(),
tileset->GetTileWidth(), tileset->GetTileHeight(),
tileset_textures[tileset->GetName()]
);
app->getRenderSystem().getDebugConsole()<<"\n"<<"Added tilemap layer "<<layer->GetName()<<" with tileset "<<tileset->GetName()<<" W:"<<tiles->getMapWidth()<<" H:"<<tiles->getMapHeight();
}
// finally, set the tile
tile_id -= tileset->GetFirstGid();
if(tiles) tiles->setTile( x, y, tile_id );
// callback
if( tile_callback ){
bea::PropertyContainer props;
props["id"] = tile_id;
props["tilemap"] = tiles;
props["x"] = x;
props["y"] = y;
props["layer"] = layer->GetName();
props["tile_width"] = tileset->GetTileWidth();
props["tile_height"] = tileset->GetTileHeight();
auto tile = tileset->GetTile(tile_id);
if( tile != 0 ){
auto tile_props = tile->GetProperties();
if( !tile_props.Empty() ){
auto list = tile_props.GetList();
for( auto pit = list.begin(); pit != list.end(); ++pit ){
props[ pit->first ] = pit->second;
}
}
}
tile_callback(props);
}
}
}
if( tiles ) {
tiles->setDepth( tiles->getDepth() + (float(i)/10.0f) );
tiles->update();
}
}
// Go through the object groups
if( object_callback ){
for (int i = 0; i < map.GetNumObjectGroups(); ++i) {
const Tmx::ObjectGroup *objectGroup = map.GetObjectGroup(i);
for (int j = 0; j < objectGroup->GetNumObjects(); ++j) {
const Tmx::Object *object = objectGroup->GetObject(j);
bea::PropertyContainer props;
props["name"] = object->GetName();
props["group"] = objectGroup->GetName();
props["type"] = object->GetType();
props["x"] = object->GetX();
props["y"] = object->GetY();
//.........这里部分代码省略.........
示例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: add
/**
@b Parameters:
@arg @b pNewTmxMap Pointer no a new IND_TmxMap object.
@arg @b pName TmxMap filename
@b Operation:
This function returns 1 (true) if the image object passed as a parameter
exists and is added successfully to the manager.
It supports the following file formats:
tmx.
*/
bool IND_TmxMapManager::add(IND_TmxMap *pNewTmxMap,const char *pName) {
g_debug->header("Loading TmxMap", DebugApi::LogHeaderBegin);
if(!pName) {
g_debug->header("Invalid File name provided (null)",DebugApi::LogHeaderError);
return 0;
}
g_debug->header("File name:", DebugApi::LogHeaderInfo);
g_debug->dataChar(pName, 1);
if (!_ok) {
writeMessage();
return 0;
}
// ----- Obtaining and checking file extension -----
char ext [128];
getExtensionFromName(pName,ext);
if (!checkExtImage(ext)){
g_debug->header("Unknown extension", DebugApi::LogHeaderError);
return 0;
}
// ----- Load TmxMap -----
Tmx::Map *map = new Tmx::Map();
map->ParseFile(pName);
if (map->HasError()) {
g_debug->header("Error code:", 2);
//g_debug->dataChar(map->GetErrorCode(), 1); //TODO
g_debug->header("Error text:", 2);
g_debug->dataChar(map->GetErrorText().c_str(), 1);
DISPOSE(map);
return 0;
}
// ----- Load TmxMap tilesetimagesheet -----
string tmxPath;
string imagePath;
string s = string(pName);
size_t lastPosTemp = s.find_last_of("\\/");
if(lastPosTemp == string::npos){
tmxPath = "./";
}
else{
tmxPath = s.substr(0, lastPosTemp + 1);
}
imagePath = tmxPath.append(map->GetTileset(0)->GetImage()->GetSource()); // FIXME : this is very wrong we need to store an array of images instead.... i.e NO '0'
// ----- Load image -----
FREE_IMAGE_FORMAT imgFormat = FreeImage_GetFileType(imagePath.c_str(), 0);
if (FIF_UNKNOWN == imgFormat) {
g_debug->header("Image not found", 2);
DISPOSE(map);
return 0;
}
FIBITMAP* image = FreeImage_Load(imgFormat, imagePath.c_str(), 0);
if (!image) {
g_debug->header("Image could not be loaded", 2);
DISPOSE(map);
return 0;
}
// ----- Attributes -----
pNewTmxMap->setTmxMapHandle(map);
pNewTmxMap->setName(pName);
pNewTmxMap->setImage(image); // FIXME should be added to an array
pNewTmxMap->setImagePath(imagePath.c_str()); // FIXME should be added to an array
//.........这里部分代码省略.........
示例6: 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);
//.........这里部分代码省略.........
示例7: Load
bool Level::Load(const std::string& filename) {
Tmx::Map map;
map.ParseFile(filename);
if(map.HasError()) {
Debug::logger->message("Error while loading level %s: %s\n", filename.c_str(), map.GetErrorText().c_str());
return false;
}
_width = map.GetWidth();
_height = map.GetHeight();
_tileWidth = map.GetTileWidth();
_tileHeight = map.GetTileHeight();
std::map<const Tmx::Tileset*, Tileset*> tilesetMap;
for(int i = 0; i < map.GetNumTilesets(); i++) {
const Tmx::Tileset* tmxTileset = map.GetTileset(i);
Tileset* tileset = new Tileset(_tileWidth, _tileHeight);
tileset->LoadImage(map.GetFilepath() + tmxTileset->GetImage()->GetSource());
_tilesets.push_back(tileset);
tilesetMap.insert(std::pair<const Tmx::Tileset*, Tileset*>(tmxTileset, tileset));
}
_collisions = new bool[_width * _height];
for(int i = 0; i < (_width * _height); i++) {
_collisions[i] = false;
}
for(int i = 0; i < map.GetNumLayers(); i++) {
const Tmx::Layer* tmxLayer = map.GetLayer(i);
if(!strcasecmp(tmxLayer->GetName().c_str(), "collision")) {
for(int x = 0; x < _width; x++) {
for(int y = 0; y < _height; y++) {
Tmx::MapTile tile = tmxLayer->GetTile(x, y);
_collisions[y * _width + x] = tile.tilesetId > -1;
}
}
continue;
}
else if(!strcasecmp(tmxLayer->GetName().c_str(), "middle")) {
_middleLayer = i;
}
Layer* layer = new Layer(
tmxLayer->GetWidth(), tmxLayer->GetHeight(),
_tileWidth, _tileHeight);
for(int x = 0; x < layer->GetWidth(); x++) {
for(int y = 0; y < layer->GetHeight(); y++) {
Tmx::MapTile tmxTile = tmxLayer->GetTile(x, y);
MapTile tile;
if(tmxTile.tilesetId != -1) {
const Tmx::Tileset* tmxTileset = map.GetTileset(tmxTile.tilesetId);
tile.id = tmxTile.id;
tile.tileset = tilesetMap.find(tmxTileset)->second;
} else {
tile.id = 0;
tile.tileset = NULL;
}
layer->SetTile(x, y, tile);
}
}
_layers.push_back(layer);
}
if(_middleLayer == -1) {
_middleLayer = int(floor(float(_layers.size()) / 2.0f)); // <-- nasty
}
for(int i = 0; i < map.GetNumObjectGroups(); i++) {
const Tmx::ObjectGroup* tmxGroup = map.GetObjectGroup(i);
for(int j = 0; j < tmxGroup->GetNumObjects(); j++) {
const Tmx::Object* tmxObject = tmxGroup->GetObject(j);
if(!strncasecmp(tmxObject->GetName().c_str(), "NPC", 3)) {
NPC* npc = new NPC(this);
npc->LoadSprites(tmxObject->GetProperties().GetLiteralProperty("image").c_str());
npc->SetXY(tmxObject->GetX(), tmxObject->GetY());
_npcs.push_back(npc);
}
else if(!strncasecmp(tmxObject->GetName().c_str(), "Warp", 4)) {
Warp* warp = new Warp();
warp->SetXY(tmxObject->GetX(), tmxObject->GetY());
warp->SetWidthHeight(tmxObject->GetWidth(), tmxObject->GetHeight());
warp->SetTargetMap(tmxObject->GetProperties().GetLiteralProperty("map").c_str());
warp->SetTargetX(tmxObject->GetProperties().GetNumericProperty("x") * 32);
warp->SetTargetY(tmxObject->GetProperties().GetNumericProperty("y") * 32);
_warps.push_back(warp);
}
}
}
std::map<std::string, std::string> mapProps = map.GetProperties().GetList();
for(std::map<std::string, std::string>::iterator i = mapProps.begin(); i != mapProps.end(); ++i) {
//.........这里部分代码省略.........