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


C++ Sprite::getGlobalBounds方法代码示例

本文整理汇总了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;
 }
开发者ID:StylishTriangles,项目名称:TadzikEngine,代码行数:7,代码来源:jumper.hpp

示例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));
}
开发者ID:DevelopersGuild,项目名称:bird-squad,代码行数:27,代码来源:Overlap.cpp

示例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;
 }
开发者ID:Unaimend,项目名称:Pong,代码行数:31,代码来源:collision.cpp

示例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));
}
开发者ID:DevelopersGuild,项目名称:Jumping-Anthony,代码行数:29,代码来源:Overlap.cpp

示例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);
    }
}
开发者ID:esenti,项目名称:labshooter,代码行数:9,代码来源:main.cpp

示例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);
}
开发者ID:vihanchaudhry,项目名称:Cookie-game,代码行数:10,代码来源:Overlap.cpp

示例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))
	);
}
开发者ID:kirbyUK,项目名称:platformer,代码行数:11,代码来源:dynamicBlock.cpp

示例8: bombsCollision

bool Game::bombsCollision(sf::Sprite characterSprite, sf::Sprite sprite)
{
	if (characterSprite.getGlobalBounds().intersects(sprite.getGlobalBounds()))
	{
		myLives -= 1;
		return true;
	}
	else
	{
		return false;
	}
}
开发者ID:Ramizen,项目名称:firstGame,代码行数:12,代码来源:Game.cpp

示例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;
	}
开发者ID:Oramac26,项目名称:stare,代码行数:12,代码来源:Game.hpp

示例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;
		}
	}
}
开发者ID:rzsavilla,项目名称:Monk,代码行数:28,代码来源:Spawner.cpp

示例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();
 }
开发者ID:ZwodahS,项目名称:LD28,代码行数:8,代码来源:Button.cpp

示例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);
}
开发者ID:DanielCordell,项目名称:MathsRevisionTool-Coursework-2015,代码行数:13,代码来源:CScreen.cpp

示例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;
}
开发者ID:cubemoon,项目名称:GD,代码行数:44,代码来源:Collisions.cpp

示例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)));
    }
开发者ID:Tassa,项目名称:PokemonGamma,代码行数:10,代码来源:usefullSFMLThings.cpp

示例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;
                                }
开发者ID:RichardSlade,项目名称:MscFinalProject,代码行数:11,代码来源:Item.hpp


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