本文整理汇总了C++中sf::Sprite::getGlobalBounds方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::getGlobalBounds方法的具体用法?C++ Sprite::getGlobalBounds怎么用?C++ Sprite::getGlobalBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::getGlobalBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testForStanding
bool testForStanding(sf::Sprite sp2) {
if ((sp2.getGlobalBounds().left+sp2.getGlobalBounds().width > sprite.getPosition().x) &&
(sp2.getGlobalBounds().left < sprite.getPosition().x+sprite.getTextureRect().width*sprite.getScale().x)) {
return true;
}
return false;
}
示例2: overlap
bool overlap(sf::Sprite& sprite1, sf::Sprite& sprite2)
{
sf::FloatRect rectangle1 = sprite1.getGlobalBounds();
sf::FloatRect rectangle2 = sprite2.getGlobalBounds();
// Rectangles with negative dimensions are allowed, so we must handle them correctly
// Compute the min and max of the first rectangle on both axes
float r1MinX = std::min(rectangle1.left, rectangle1.left + rectangle1.width);
float r1MaxX = std::max(rectangle1.left, rectangle1.left + rectangle1.width);
float r1MinY = std::min(rectangle1.top, rectangle1.top + rectangle1.height);
float r1MaxY = std::max(rectangle1.top, rectangle1.top + rectangle1.height);
// Compute the min and max of the second rectangle on both axes
float r2MinX = std::min(rectangle2.left, rectangle2.left + rectangle2.width);
float r2MaxX = std::max(rectangle2.left, rectangle2.left + rectangle2.width);
float r2MinY = std::min(rectangle2.top, rectangle2.top + rectangle2.height);
float r2MaxY = std::max(rectangle2.top, rectangle2.top + rectangle2.height);
// Compute the intersection boundaries
float interLeft = std::max(r1MinX, r2MinX);
float interTop = std::max(r1MinY, r2MinY);
float interRight = std::min(r1MaxX, r2MaxX);
float interBottom = std::min(r1MaxY, r2MaxY);
// If the intersection is valid (positive non zero area), then there is an intersection
return ((interLeft <= interRight) && (interTop <= interBottom));
}
示例3: PixelPerfectTest
bool PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit) {
sf::FloatRect Intersection;
if (Object1.getGlobalBounds().intersects(Object2.getGlobalBounds(), Intersection)) {
sf::IntRect O1SubRect = Object1.getTextureRect();
sf::IntRect O2SubRect = Object2.getTextureRect();
sf::Uint8* mask1 = Bitmasks.GetMask(Object1.getTexture());
sf::Uint8* mask2 = Bitmasks.GetMask(Object2.getTexture());
// Loop through our pixels
for (int i = Intersection.left; i < Intersection.left+Intersection.width; i++) {
for (int j = Intersection.top; j < Intersection.top+Intersection.height; j++) {
sf::Vector2f o1v = Object1.getInverseTransform().transformPoint(i, j);
sf::Vector2f o2v = Object2.getInverseTransform().transformPoint(i, j);
// Make sure pixels fall within the sprite's subrect
if (o1v.x > 0 && o1v.y > 0 && o2v.x > 0 && o2v.y > 0 &&
o1v.x < O1SubRect.width && o1v.y < O1SubRect.height &&
o2v.x < O2SubRect.width && o2v.y < O2SubRect.height) {
if (Bitmasks.GetPixel(mask1, Object1.getTexture(), (int)(o1v.x)+O1SubRect.left, (int)(o1v.y)+O1SubRect.top) > AlphaLimit &&
Bitmasks.GetPixel(mask2, Object2.getTexture(), (int)(o2v.x)+O2SubRect.left, (int)(o2v.y)+O2SubRect.top) > AlphaLimit)
return true;
}
}
}
}
return false;
}
示例4: overlap
bool overlap(sf::Sprite& sprite1, sf::Sprite& sprite2)
{
sf::FloatRect rectangle1 = sprite1.getGlobalBounds();
sf::FloatRect rectangle2 = sprite2.getGlobalBounds();
// Rectangles with negative dimensions are allowed, so we must handle them correctly
// Compute the min and max of the first rectangle on both axes
float r1MinX = std::min(rectangle1.left, rectangle1.left + rectangle1.width); //left
float r1MaxX = std::max(rectangle1.left, rectangle1.left + rectangle1.width);//right
float r1MinY = std::min(rectangle1.top, rectangle1.top + rectangle1.height); // top
float r1MaxY = std::max(rectangle1.top, rectangle1.top + rectangle1.height); // bottom of the maincharactersprite
// Compute the min and max of the second rectangle on both axes
float r2MinX = std::min(rectangle2.left, rectangle2.left + rectangle2.width);//left
float r2MaxX = std::max(rectangle2.left, rectangle2.left + rectangle2.width);//right
float r2MinY = std::min(rectangle2.top, rectangle2.top + rectangle2.height);//top of the blocksprite
float r2MaxY = std::max(rectangle2.top, rectangle2.top + rectangle2.height); // bottom
// Compute the intersection boundaries
float interLeft = std::max(r1MinX, r2MinX);//get the most right one
float interTop = std::max(r1MinY, r2MinY);//get the higher one
float interRight = std::min(r1MaxX, r2MaxX);// get the most left one
float interBottom = std::min(r1MaxY, r2MaxY);// the the lowest one
//want to check if bottom of the mainCharacterSprite and top of the Block sprite are overlaping
// If the intersection is valid (positive non zero area), then there is an intersection
return ((interLeft <= interRight) && (interTop <= interBottom));
}
示例5: move
void move(float x, float y, sf::Sprite& sprite, sf::Sprite obstacle)
{
sprite.move(x, y);
if(sprite.getGlobalBounds().intersects(obstacle.getGlobalBounds()))
{
sprite.move(-x, -y);
}
}
示例6: overlap
bool overlap(sf::Sprite& sprite1, sf::Sprite& sprite2)
{
sf::FloatRect rectangle1 = sprite1.getGlobalBounds(); //get top left corner position and bottom right position
sf::FloatRect rectangle2 = sprite2.getGlobalBounds();
return rectangle1.left <= (rectangle2.left + rectangle2.width) &&
rectangle2.left <= (rectangle1.left + rectangle1.width) &&
rectangle1.top <= (rectangle2.top + rectangle2.height) &&
rectangle2.top <= (rectangle1.top + rectangle1.height);
}
示例7: getDetectionBox
sf::FloatRect DynamicBlock::getDetectionBox(sf::Sprite& p) const
{
//Create a box around the block with space for the player:
return sf::FloatRect
(
(_shape.getPosition().x - (p.getGlobalBounds().width / 2)),
_shape.getPosition().y,
(_shape.getSize().x + p.getGlobalBounds().width),
(_shape.getSize().y + (p.getGlobalBounds().height / 2))
);
}
示例8: bombsCollision
bool Game::bombsCollision(sf::Sprite characterSprite, sf::Sprite sprite)
{
if (characterSprite.getGlobalBounds().intersects(sprite.getGlobalBounds()))
{
myLives -= 1;
return true;
}
else
{
return false;
}
}
示例9: CorrectM
bool CorrectM(sf::Sprite &s, const sf::RenderWindow &w)
{
if (
sf::Mouse::getPosition(w).x > s.getGlobalBounds().left &&
sf::Mouse::getPosition(w).y > s.getGlobalBounds().top &&
sf::Mouse::getPosition(w).x < s.getGlobalBounds().left + s.getGlobalBounds().width &&
sf::Mouse::getPosition(w).y < s.getGlobalBounds().top + s.getGlobalBounds().height
)
return 1;
else
return 0;
}
示例10: update
void Spawner::update(sf::Time h, InputHandler& input, int& score, int& iState, sf::Sprite& energy) {
// Check for clicks
std::shared_ptr<sf::RectangleShape> pMouseArea = nullptr;
if (input.bLeftClick)
{
pMouseArea = std::shared_ptr<sf::RectangleShape>(new sf::RectangleShape);
pMouseArea->setSize(sf::Vector2f(5, 5));
sf::Vector2i mousePosition = input.mousePos;
pMouseArea->setPosition(mousePosition.x, mousePosition.y);
}
// Update velocity
for (int i = 0; i < entitiesSpawned.size(); i++) {
entitiesSpawned.at(i).update(h);
// Check for game over
if (energy.getGlobalBounds().intersects(entitiesSpawned.at(i).getGlobalBounds()))
iState = 3;
// Check for kills
if (pMouseArea != nullptr && entitiesSpawned.at(i).getGlobalBounds().intersects(pMouseArea->getGlobalBounds()))
{
// Kill
entitiesSpawned.erase(entitiesSpawned.begin() + i);
// Update score
score += 10;
}
}
}
示例11: updatePosition
Button::Button(sf::Sprite selectedSprite, sf::Sprite unselectedSprite)
:_buttonType(TSB), _state(0), _internalStateManaged(true)
{
_sprites.push_back(unselectedSprite);
_sprites.push_back(selectedSprite);
_clickBound = unselectedSprite.getGlobalBounds();
updatePosition();
}
示例12: buttonHighlightDetect
// Initialising functions
// Detects if a mouse is hovering over a button based on the mouse position, and if it is, tints the button slightly grey.
// If it isn't then the tint is removed.
// This version of the function is for sprites
void cScreen::buttonHighlightDetect(sf::Vector2i &mousePos, sf::Sprite &button) {
// If the mouse's current position is within the bounds of the button
if (button.getGlobalBounds().contains(mousePos.x, mousePos.y)) {
// Set the tint of the button to RGB color 200,200,200
button.setColor(sf::Color(200, 200, 200));
}
// If not set the tint of the button to white
else button.setColor(sf::Color::White);
}
示例13: PixelPerfectTest
bool PixelPerfectTest( const sf::Sprite& object1, const sf::Sprite& object2, sf::Uint8 AlphaLimit, const sf::Image & object1CollisionMask, const sf::Image & object2CollisionMask )
{
sf::FloatRect intersection;
if ( object1.getGlobalBounds().intersects( object2.getGlobalBounds(), 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::Vector2f o1v;
sf::Vector2f o2v;
//Loop through our pixels
for ( int i = intersection.left; i < intersection.left+intersection.width; i++ ) //4ian : Rect now uses width/height.
{
for ( int j = intersection.top; j < intersection.top+intersection.height; j++ ) //4ian : Rect now uses width/height.
{
o1v = object1.getInverseTransform().transformPoint( i, j ); //Creating objects each loop :(
o2v = object2.getInverseTransform().transformPoint( i, j );
//Hack to make sure pixels fall within the Sprite's Image
if ( o1v.x > 0 && o1v.y > 0 && o2v.x > 0 && o2v.y > 0 &&
o1v.x < object1CollisionMask.getSize().x && o1v.y < object1CollisionMask.getSize().y &&
o2v.x < object2CollisionMask.getSize().x && o2v.y < object2CollisionMask.getSize().y )
{
//If both sprites have opaque pixels at the same point we've got a hit
if (( object1CollisionMask.getPixel( static_cast<int>( o1v.x ), static_cast<int>( o1v.y ) ).a > AlphaLimit ) &&
( object2CollisionMask.getPixel( static_cast<int>( o2v.x ), static_cast<int>( o2v.y ) ).a > AlphaLimit ) )
{
return true;
}
}
}
}
return false;
}
return false;
}
示例14:
void Sprite2VertexArray(const sf::Sprite & sprite,sf::VertexArray & vertices)
{
sf::IntRect texBox = sprite.getTextureRect();
sf::FloatRect box = sprite.getGlobalBounds();
vertices.append(sf::Vertex(sf::Vector2f(box.left, box.top), sf::Vector2f((float)texBox.left, (float)texBox.top)));
vertices.append(sf::Vertex(sf::Vector2f(box.left, box.top + box.height), sf::Vector2f((float)texBox.left, (float)(texBox.top + texBox.height))));
vertices.append(sf::Vertex(sf::Vector2f(box.left + box.width, box.top + box.height), sf::Vector2f((float)(texBox.left + texBox.width), (float)(texBox.top + texBox.height))));
vertices.append(sf::Vertex(sf::Vector2f(box.left + box.width, box.top), sf::Vector2f((float)(texBox.left + texBox.width), (float)texBox.top)));
}
示例15: getBounds
const sf::FloatRect getBounds()
{
sf::FloatRect tempRect = sprite.getGlobalBounds();
tempRect.top -= ObstacleBorder;
tempRect.left -= ObstacleBorder;
tempRect.width += ObstacleBorder;
tempRect.height += ObstacleBorder;
return tempRect;
}