本文整理汇总了C++中sf::Sprite::GetSubRect方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::GetSubRect方法的具体用法?C++ Sprite::GetSubRect怎么用?C++ Sprite::GetSubRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::GetSubRect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool np::Collision::BoundingBoxColl(sf::Sprite &object1, sf::Sprite &object2)
{
leftA = object1.GetPosition().x;
rightA = object1.GetPosition().x + object1.GetSubRect().GetWidth();
topA = object1.GetPosition().y;
bottomA = object1.GetPosition().y + object1.GetSubRect().GetHeight();
leftB = object2.GetPosition().x;
rightB = object2.GetPosition().x + object2.GetSubRect().GetWidth();
topB = object2.GetPosition().y;
bottomB = object2.GetPosition().y + object2.GetSubRect().GetHeight();
if(bottomA <= topB)
return false;
if(topA >= bottomB)
return false;
if(leftA >= rightB)
return false;
if(rightA <= leftB)
return false;
return true;
}
示例2: PixelPerfectTest
bool Collision::PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit) {
//Get AABBs of the two sprites
sf::IntRect Object1AABB = GetAABB(Object1);
sf::IntRect Object2AABB = GetAABB(Object2);
sf::IntRect Intersection;
if (Object1AABB.Intersects(Object2AABB, &Intersection)) {
//We've got an intersection we need to process the pixels
//In that Rect.
//Bail out now if AlphaLimit = 0
if (AlphaLimit == 0) return true;
//There are a few hacks here, sometimes the TransformToLocal returns negative points
//Or Points outside the image. We need to check for these as they print to the error console
//which is slow, and then return black which registers as a hit.
sf::IntRect O1SubRect = Object1.GetSubRect();
sf::IntRect O2SubRect = Object2.GetSubRect();
sf::Vector2i O1SubRectSize(O1SubRect.GetWidth(), O1SubRect.GetHeight());
sf::Vector2i O2SubRectSize(O2SubRect.GetWidth(), O2SubRect.GetHeight());
sf::Vector2f o1v;
sf::Vector2f o2v;
//Loop through our pixels
for (int i = Intersection.Left; i < Intersection.Right; i++) {
for (int j = Intersection.Top; j < Intersection.Bottom; j++) {
o1v = Object1.TransformToLocal(sf::Vector2f(i, j)); //Creating Objects each loop :(
o2v = Object2.TransformToLocal(sf::Vector2f(i, j));
//Hack to make sure pixels fall withint the Sprite's Image
if (o1v.x > 0 && o1v.y > 0 && o2v.x > 0 && o2v.y > 0 &&
o1v.x < O1SubRectSize.x && o1v.y < O1SubRectSize.y &&
o2v.x < O2SubRectSize.x && o2v.y < O2SubRectSize.y) {
//If both sprites have opaque pixels at the same point we've got a hit
if ((Object1.GetPixel(static_cast<int> (o1v.x), static_cast<int> (o1v.y)).a > AlphaLimit) &&
(Object2.GetPixel(static_cast<int> (o2v.x), static_cast<int> (o2v.y)).a > AlphaLimit)) {
return true;
}
}
}
}
return false;
}
return false;
}
示例3: GetBoundingBox
/*!
* \param Obj The object
* \return The bounding box of the object
*/
sf::IntRect Collision::GetBoundingBox(const sf::Sprite &Obj)
{
const sf::Vector2f &Position(Obj.GetPosition());
const sf::IntRect &SubRect(Obj.GetSubRect());
return sf::IntRect(Position.x, Position.y, Position.x + SubRect.GetWidth(),
Position.y + SubRect.GetHeight());
}
示例4: getIntRect
sf::IntRect Colision::getIntRect(const sf::Sprite &sprite)
{
const sf::Vector2f &pos(sprite.GetPosition());
const sf::IntRect &sub_rect(sprite.GetSubRect());
sf::IntRect int_rect((int)pos.x, (int)pos.y, (int)(pos.x + sub_rect.GetWidth()), (int)(pos.y + sub_rect.GetHeight()));
return (int_rect);
}