本文整理汇总了C++中TileSet::GetTileHitboxRef方法的典型用法代码示例。如果您正苦于以下问题:C++ TileSet::GetTileHitboxRef方法的具体用法?C++ TileSet::GetTileHitboxRef怎么用?C++ TileSet::GetTileHitboxRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileSet
的用法示例。
在下文中一共展示了TileSet::GetTileHitboxRef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ImportTileMap
//.........这里部分代码省略.........
tileMap.SetTile(i, x, y, layer->GetTileId(x, y));
}
}
}
}
gd::LogStatus(_("Tilemap content importation completed."));
}
//Import the hitboxes
if(importHitboxes)
{
const Tmx::Tileset *importedTileset = m_map->GetTileset(0);
//Set all tiles not collidable in the tileset
tileSet.ResetHitboxes();
for(std::size_t i = 0; i < tileSet.GetTilesCount(); i++)
tileSet.SetTileCollidable(i, false);
if(!importTileSetConf && !importTileSetImage)
CheckTilesCount(tileSet);
bool hasMoreThanOneObjectPerTile = false;
bool hasNotPolygoneObject = false;
bool hasNotConvexPolygon = false;
for(auto it = importedTileset->GetTiles().cbegin();
it != importedTileset->GetTiles().cend();
++it)
{
const Tmx::Tile *importedTile = *it;
if(importedTile->GetId() < tileSet.GetTilesCount()) //Check if the tileset has enough tiles to receive the imported hitboxes
{
if(importedTile->HasObjects())
{
//Set the tile collidable and gets its hitbox
tileSet.SetTileCollidable(importedTile->GetId(), true);
TileHitbox &tileHitbox = tileSet.GetTileHitboxRef(importedTile->GetId());
//Warn the user if more than one hitbox per tile is found
if(importedTile->GetNumObjects() > 1)
hasMoreThanOneObjectPerTile = true;
const Tmx::Object *importedObj = importedTile->GetObject(0);
if(!importedObj->GetPolyline() && !importedObj->GetEllipse())
{
Polygon2d polygonHitbox;
if(!importedObj->GetPolygon())
{
//This is a rectangle
polygonHitbox = Polygon2d::CreateRectangle(importedObj->GetWidth(), importedObj->GetHeight());
polygonHitbox.Move(
importedObj->GetWidth() / 2.f,
importedObj->GetHeight() / 2.f
);
}
else
{
//This is a polygon
const Tmx::Polygon *importedPolygon = importedObj->GetPolygon();
for(int i = 0; i < importedPolygon->GetNumPoints(); i++)
{
polygonHitbox.vertices.emplace_back(
importedPolygon->GetPoint(i).x,
importedPolygon->GetPoint(i).y
);
}
}
polygonHitbox.Move(importedObj->GetX(), importedObj->GetY());
polygonHitbox.Rotate(importedObj->GetRot());
if(polygonHitbox.IsConvex())
tileHitbox.hitbox = polygonHitbox;
else
hasNotConvexPolygon = true;
}
else
{
//This is not a supported shape
hasNotPolygoneObject = true;
}
}
}
}
if(hasMoreThanOneObjectPerTile)
gd::LogWarning(_("Some tiles have more than 1 hitbox. Only the first one is imported."));
if(hasNotPolygoneObject)
gd::LogWarning(_("Some tiles have a polyline or a ellipsis hitbox. Only rectangle and polygon hitboxes are supported."));
if(hasNotConvexPolygon)
gd::LogWarning(_("Some tiles have a concave polygon. It has been ignored and set to a rectangular hitbox as this object only supports convex hitboxes for tiles."));
gd::LogStatus(_("Tiles hitboxes importation completed."));
}
return true;
}