本文整理汇总了C++中Tileset::GetTileX方法的典型用法代码示例。如果您正苦于以下问题:C++ Tileset::GetTileX方法的具体用法?C++ Tileset::GetTileX怎么用?C++ Tileset::GetTileX使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tileset
的用法示例。
在下文中一共展示了Tileset::GetTileX方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IsRectCollidesTile
bool PhyTileEngine::IsRectCollidesTile(core::recti rect_, video::SColor blockType_, int tileX, int tileY)
{
const LayerTile* layerTile = m_physicLayerTile->GetLayerTile(tileX, tileY);
if (layerTile->GetTilesetId() >= 0)
{
Tileset* tileset = m_tilemap->GetTileset( layerTile->GetTilesetId() );
video::ITexture* tilesetText = tileset->GetTexture( m_driver );
// Get intersection with physic layer image to be in bounds
core::recti srcRect = rect_;
core::recti tileRect( tileX * m_tilemap->GetTileWidth(), tileY * m_tilemap->GetTileHeight(), (tileX + 1) * m_tilemap->GetTileWidth(), (tileY + 1) * m_tilemap->GetTileHeight() );
//srcRect.clipAgainst(tileRect);
srcRect.UpperLeftCorner.X = core::max_( rect_.UpperLeftCorner.X, tileRect.UpperLeftCorner.X);
srcRect.LowerRightCorner.X = core::min_( rect_.LowerRightCorner.X, tileRect.LowerRightCorner.X);
srcRect.UpperLeftCorner.Y = core::max_( rect_.UpperLeftCorner.Y, tileRect.UpperLeftCorner.Y);
srcRect.LowerRightCorner.Y = core::min_( rect_.LowerRightCorner.Y, tileRect.LowerRightCorner.Y);
// move to tileset coords
s32 rectWidth = srcRect.getWidth();
s32 rectHeight = srcRect.getHeight();
srcRect.UpperLeftCorner.X = (srcRect.UpperLeftCorner.X % m_tilemap->GetTileWidth()) + tileset->GetTileX(layerTile->GetTileId()) * m_tilemap->GetTileWidth();
srcRect.UpperLeftCorner.Y = (srcRect.UpperLeftCorner.Y % m_tilemap->GetTileHeight()) + tileset->GetTileY(layerTile->GetTileId()) * m_tilemap->GetTileHeight();
srcRect.LowerRightCorner.X = srcRect.UpperLeftCorner.X + rectWidth;
srcRect.LowerRightCorner.Y = srcRect.UpperLeftCorner.Y + rectHeight;
u8* pixelData = static_cast<u8 *>( tilesetText->lock(true) );
core::dimension2du textSize = tilesetText->getSize();
u32 pixelSize = tilesetText->getPitch() / textSize.Width;
bool isCollision = false;
//!!!NOTE: suppose format video::ECOLOR_FORMAT::ECF_A8R8G8B8
for( s32 x = srcRect.UpperLeftCorner.X; x < srcRect.LowerRightCorner.X && !isCollision; ++x )
for( s32 y = srcRect.UpperLeftCorner.Y; y < srcRect.LowerRightCorner.Y && !isCollision; ++y )
{
s32 index = y * tilesetText->getPitch() + x * pixelSize;
video::SColor color( *((u32*)(pixelData + index)) );
if( color == blockType_ )
{
isCollision = true;
}
}
tilesetText->unlock();
return isCollision;
}
return false;
}