本文整理汇总了C++中Tileset::GetTileHeight方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::GetTileHeight方法的具体用法?C++ Tileset::GetTileHeight怎么用?C++ Tileset::GetTileHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tileset
的用法示例。
在下文中一共展示了Tileset::GetTileHeight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseElement
void TileLayer::parseElement(tinyxml2::XMLElement* layerElement, Map* map)
{
// Get properties
auto properties = layerElement->FirstChildElement("properties");
if(properties != 0)
parseProperties(properties);
m_name = layerElement->Attribute("name");
m_width = layerElement->UnsignedAttribute("width");
m_height = layerElement->UnsignedAttribute("height");
// Parse data
unsigned int x = 0;
unsigned int y = 0;
auto tile = layerElement->FirstChildElement("data")->FirstChildElement("tile");
while(tile != 0)
{
unsigned int gid = tile->UnsignedAttribute("gid");
// Read out the flags
bool flipped_horizontally = (gid & FLIPPED_HORIZONTALLY_FLAG) != 0;
bool flipped_vertically = (gid & FLIPPED_VERTICALLY_FLAG) != 0;
// TODO: implement this
//bool flipped_diagonally = (gid & FLIPPED_DIAGONALLY_FLAG) != 0;
// Clear the flags
gid &= ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG
| FLIPPED_DIAGONALLY_FLAG);
// Find correct tileset
for(int i = map->tilesets.size() - 1; i >= 0; --i)
{
Tileset* tileset = map->tilesets[i];
if(tileset->GetFirstGID() <= gid)
{
if(x >= map->GetWidth())
{
x = 0;
y++;
}
const pmath::Rect t(static_cast<float>(x * tileset->GetTileWidth()), static_cast<float>(y * tileset->GetTileHeight()),
static_cast<float>(tileset->GetTileWidth()), static_cast<float>(tileset->GetTileHeight()));
auto tile = new Tile(t);
if(flipped_horizontally)
tile->transform.SetScale(-1, tile->transform.GetScale().y);
if(flipped_vertically)
tile->transform.SetScale(tile->transform.GetScale().x, -1);
tile->parent = static_cast<GameObject*>(map);
const pmath::Rect texCoords = tileset->GetTile(gid - tileset->GetFirstGID());
m_tiles.push_back(tile);
m_spriteBatches.at(tileset->GetTexture())->AddSprite(&tile->transform, "", pmath::Vec4(1,1,1,1), texCoords);
x++;
break;
}
}
tile = tile->NextSiblingElement("tile");
}
}
示例2: parseElement
void TileLayer::parseElement(tinyxml2::XMLElement* layerElement, Map* map)
{
// Get properties
auto properties = layerElement->FirstChildElement("properties");
if(properties != 0)
parseProperties(properties);
m_name = layerElement->Attribute("name");
m_width = layerElement->UnsignedAttribute("width");
m_height = layerElement->UnsignedAttribute("height");
if (layerElement->Attribute("visible") != 0)
{
m_active = layerElement->IntAttribute("visible") == 0 ? false : true;
}
else
m_active = true;
// Parse data
unsigned int x = 0;
unsigned int y = 0;
auto tile = layerElement->FirstChildElement("data")->FirstChildElement("tile");
while(tile != 0)
{
unsigned int gid = tile->UnsignedAttribute("gid");
// Go to the next "line"
if (x >= map->GetWidth())
{
x = 0;
y++;
}
// Tile is "empty space"
if (gid == 0)
{
x++;
tile = tile->NextSiblingElement("tile");
continue;
}
// Read out the flags
const bool flipped_horizontally = (gid & FLIPPED_HORIZONTALLY_FLAG) != 0;
const bool flipped_vertically = (gid & FLIPPED_VERTICALLY_FLAG) != 0;
const bool flipped_diagonally = (gid & FLIPPED_DIAGONALLY_FLAG) != 0;
// Clear the flags
gid &= ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG
| FLIPPED_DIAGONALLY_FLAG);
// Find correct tileset
for(int i = map->tilesets.size() - 1; i >= 0; --i)
{
Tileset* tileset = map->tilesets[i].get();
if (tileset->GetFirstGID() <= gid)
{
const pmath::Rect t(static_cast<float>(x * tileset->GetTileWidth()), static_cast<float>(y * tileset->GetTileHeight()),
static_cast<float>(tileset->GetTileWidth()), static_cast<float>(tileset->GetTileHeight()));
auto tile = new Tile(t);
if (flipped_diagonally)
{
if (flipped_horizontally && flipped_vertically)
{
tile->transform.Rotate(90);
tile->transform.SetScale(-1, tile->transform.GetScale().y);
}
else if (flipped_horizontally)
{
tile->transform.Rotate(90);
}
else if (flipped_vertically)
{
tile->transform.Rotate(-90);
}
else
{
tile->transform.Rotate(-90);
tile->transform.SetScale(-1, tile->transform.GetScale().y);
}
}
else
{
if (flipped_horizontally)
tile->transform.SetScale(-1, tile->transform.GetScale().y);
if (flipped_vertically)
tile->transform.SetScale(tile->transform.GetScale().x, -1);
}
map->AddChild(tile);
const pmath::Rect texCoords = tileset->GetTile(gid - tileset->GetFirstGID());
m_tiles.push_back(tile);
m_spriteBatches.at(tileset->GetTexture())->AddSprite(&tile->transform, "", pmath::Vec4(1, 1, 1, 1), texCoords);
x++;
break;
}
}
//.........这里部分代码省略.........