当前位置: 首页>>代码示例>>C++>>正文


C++ Tileset::GetTile方法代码示例

本文整理汇总了C++中Tileset::GetTile方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::GetTile方法的具体用法?C++ Tileset::GetTile怎么用?C++ Tileset::GetTile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tileset的用法示例。


在下文中一共展示了Tileset::GetTile方法的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");
	}
}
开发者ID:RafaOP,项目名称:CastleOfValhalla,代码行数:64,代码来源:TileLayer.cpp

示例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;
            }
		}
//.........这里部分代码省略.........
开发者ID:Freeman117,项目名称:Orbital-DefenseRemade,代码行数:101,代码来源:TileLayer.cpp


注:本文中的Tileset::GetTile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。