本文整理汇总了C++中Tile::SetPos方法的典型用法代码示例。如果您正苦于以下问题:C++ Tile::SetPos方法的具体用法?C++ Tile::SetPos怎么用?C++ Tile::SetPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tile
的用法示例。
在下文中一共展示了Tile::SetPos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadLevel
Level* LevelManager::LoadLevel (const std::string& path) {
//Load file
std::ifstream input (path);
//Ensure it opened
if (!input) {
printf ("Warning! Could not open file: %s\n", path.c_str ());
return nullptr;
}
//Get the contents
std::string fileContents;
std::string line;
while (std::getline (input, line)) fileContents += line;
//Convert to rapidxml format
std::vector<char> data = std::vector<char> (fileContents.begin (), fileContents.end ());
data.push_back ('\0');
rapidxml::xml_document<> doc;
doc.parse<rapidxml::parse_no_data_nodes> (&data[0]);
rapidxml::xml_node<>* root = doc.first_node ();
int width = atoi (root->first_attribute ("width")->value ());
int height = atoi (root->first_attribute ("height")->value ());
rapidxml::xml_node<>* tileset = root->first_node ("tileset");
Level* level = new Level (width, height, LoadTileSet (tileset->first_attribute ("path")->value ()), root->first_attribute ("name")->value ());
std::string tiles = root->first_node ("tiles")->value();
int x = 0;
int y = 0;
if (!level) {
printf ("Warning! Could not create level\n");
return nullptr;
}
for (std::string::iterator itr = tiles.begin (); itr != tiles.end (); ++itr) {
if (*itr != ' ' && *itr != '\n' && *itr != '\r' && *itr != '\t') {
Tile* tile = new Tile (GetTile ((TileType)std::atoi (&(*itr))));
tile->SetPos(Vec2{(float) x * tile->GetTileSize(), (float) y * tile->GetTileSize() });
level->AddTile (x, y, tile);
++x;
if (x % width == 0) {
x = 0;
++y;
}
}
}
App::GetInst ()->GetGOManager ()->LoadLevel (level->TileSize (), level->NumTilesX (), level->NumTilesY ());
printf ("Success: Loaded level: %s!\n", path.c_str ());
return level;
}