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


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

本文整理汇总了C++中sf::RectangleShape::getGlobalBounds方法的典型用法代码示例。如果您正苦于以下问题:C++ RectangleShape::getGlobalBounds方法的具体用法?C++ RectangleShape::getGlobalBounds怎么用?C++ RectangleShape::getGlobalBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::RectangleShape的用法示例。


在下文中一共展示了RectangleShape::getGlobalBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doMouseMove

void doMouseMove(){
    if (rect1.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
        if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect1.setFillColor(sf::Color(100,100,100));
    } else {
        rect1.setFillColor(sf::Color(200,200,200));
    }

    if (rect2.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
        if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect2.setFillColor(sf::Color(100,100,100));
    } else {
        rect2.setFillColor(sf::Color(200,200,200));
    }

    if (rect3.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
        if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect3.setFillColor(sf::Color(100,100,100));
    } else {
        rect3.setFillColor(sf::Color(200,200,200));
    }

    if (rect4.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
        if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) rect4.setFillColor(sf::Color(100,100,100));
    } else {
        rect4.setFillColor(sf::Color(200,200,200));
    }
}
开发者ID:2729StormRobotics,项目名称:StormArduino,代码行数:25,代码来源:main.cpp

示例2: arrange

void DropDown::arrange(sf::Text &text,sf::RectangleShape &shape)
{
	float ratiox = shape.getGlobalBounds().width/text.getGlobalBounds().width;
	float ratioy = (shape.getGlobalBounds().height/text.getGlobalBounds().height);
	ratioy*=0.5f;
	text.scale(ratiox,ratioy);
}
开发者ID:Glowny,项目名称:Korttipelimoottori,代码行数:7,代码来源:DropDown.cpp

示例3: CheckRectangleCollision

//Method to check collision between 2 rectangles.
bool CollisionManager::CheckRectangleCollision(sf::RectangleShape entity1, sf::RectangleShape entity2)
{
	if (entity1.getGlobalBounds().intersects(entity2.getGlobalBounds()))
		return true;

	else
		return false;
}
开发者ID:JonnyIrl,项目名称:FYP,代码行数:9,代码来源:CollisionManager.cpp

示例4: IsPossibleCollisionWithTopOrBottomSide

bool CollisionChecker::IsPossibleCollisionWithTopOrBottomSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().x+r1.getGlobalBounds().width > r2.getPosition().x
    && r1.getPosition().x < r2.getPosition().x+r2.getGlobalBounds().width){
        return true;
    }

    return false;
}
开发者ID:emSon150,项目名称:WhereAreMyEggs,代码行数:9,代码来源:CollisionChecker.cpp

示例5: IsPossibleCollisionWithLeftOrRightSide

bool CollisionChecker::IsPossibleCollisionWithLeftOrRightSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().y+r1.getGlobalBounds().height > r2.getPosition().y
    && r1.getPosition().y < r2.getPosition().y+r2.getGlobalBounds().height){
        return true;
    }

    return false;
}
开发者ID:emSon150,项目名称:WhereAreMyEggs,代码行数:9,代码来源:CollisionChecker.cpp

示例6: IsCollidingWithRightSide

bool CollisionChecker::IsCollidingWithRightSide(sf::RectangleShape &r1, sf::RectangleShape &r2)
{
    if(r1.getPosition().x <= r2.getPosition().x+r2.getGlobalBounds().width
    && r1.getPosition().x >= r2.getPosition().x
    && r1.getPosition().y+r1.getGlobalBounds().height > r2.getPosition().y
    && r1.getPosition().y < r2.getPosition().y+r2.getGlobalBounds().height){
        return true;
    }

    return false;
}
开发者ID:emSon150,项目名称:WhereAreMyEggs,代码行数:11,代码来源:CollisionChecker.cpp

示例7:

bool tr::CColisiometro::Interseccion(sf::RectangleShape obj1, sf::RectangleShape obj2, sf::RectangleShape* choque = nullptr)
{
	sf::FloatRect rect2 = obj2.getGlobalBounds();
	sf::FloatRect rect1 = obj1.getGlobalBounds();

	if (rect2.intersects(rect1))
	{
		return true;
	}else
	{
		return false;
	}
}
开发者ID:0Wind-UpBird,项目名称:Run-Ball-Run,代码行数:13,代码来源:Colisiometro.cpp

示例8: ifCollide

bool ifCollide(const sf::RectangleShape& A, const sf::RectangleShape& B)
{
	float aRad = A.getGlobalBounds().height;
	float bRad = B.getGlobalBounds().height;
	float length = (aRad + bRad)/2.f;

	sf::Vector2f aPos = A.getPosition();
	sf::Vector2f bPos = B.getPosition();
	sf::Vector2f diff = aPos - bPos;

	float magn = sqrt(diff.x*diff.x + diff.y*diff.y);

	return magn <= length;
}
开发者ID:DrJonki,项目名称:Ludum-Dare-30,代码行数:14,代码来源:PlayState.cpp

示例9: doMouseButton

void doMouseButton(sf::Mouse::Button button){
    if (button == sf::Mouse::Button::Left){
        if (rect1.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
            if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)){
                rect1.setFillColor(sf::Color::Yellow);
                doSwitchMode(Mode::SolidWhite);
            } else {
                rect1.setFillColor(sf::Color(100,100,100));
            }
        } else {
            rect1.setFillColor(sf::Color(200,200,200));
        }

        if (rect2.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
            if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)){
                rect2.setFillColor(sf::Color::Yellow);
                doSwitchMode(Mode::Marquee);
            } else {
                rect2.setFillColor(sf::Color(100,100,100));
            }
        } else {
            rect2.setFillColor(sf::Color(200,200,200));
        }

        if (rect3.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
            if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)){
                rect3.setFillColor(sf::Color::Yellow);
                doSwitchMode(Mode::ColorCycle);
            } else {
                rect3.setFillColor(sf::Color(100,100,100));
            }
        } else {
            rect3.setFillColor(sf::Color(200,200,200));
        }

        if (rect4.getGlobalBounds().contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
            if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)){
                rect4.setFillColor(sf::Color::Yellow);
                doSwitchMode(Mode::Pew);
            } else {
                rect4.setFillColor(sf::Color(100,100,100));
            }
        } else {
            rect4.setFillColor(sf::Color(200,200,200));
        }
    }
}
开发者ID:2729StormRobotics,项目名称:StormArduino,代码行数:47,代码来源:main.cpp

示例10: ClipVector

bool Ray::ClipVector(int axis, sf::RectangleShape& boxIn)
{
	float tempClipFractionLow = 0;
	float tempClipFractionHigh = 1;//temp Fractions
	

	//gets fraction of vector that fits inside of bounding box
	if(axis == 0)//x axis
	{
		tempClipFractionLow = (((boxIn.getPosition().x - boxIn.getGlobalBounds().width/2) - startPos.x)/(endPos.x - startPos.x));
		tempClipFractionHigh = (((boxIn.getPosition().x + boxIn.getGlobalBounds().width/2) - startPos.x)/(endPos.x - startPos.x));
	}
	else if(axis == 1)//y axis
	{
		tempClipFractionLow = (((boxIn.getPosition().y + boxIn.getGlobalBounds().height/2) - startPos.y)/(endPos.y - startPos.y));
		tempClipFractionHigh = (((boxIn.getPosition().y - boxIn.getGlobalBounds().height/2) - startPos.y)/(endPos.y - startPos.y));
	}
	else
	{
		return false;
	}

	if(tempClipFractionHigh < tempClipFractionLow)
	{
		swap(tempClipFractionHigh,tempClipFractionLow);
	}

	if(tempClipFractionHigh < clipFractionLow)
	{
		return false;
	}
	else
	if(tempClipFractionLow > clipFractionHigh)
	{
		return false;
	}

	clipFractionLow = max(tempClipFractionLow,clipFractionLow);
	clipFractionHigh = min(tempClipFractionHigh,clipFractionHigh);

	if(clipFractionLow > clipFractionHigh)
	{
		return false;
	}

	return true;
}
开发者ID:BenDy557,项目名称:Football,代码行数:47,代码来源:Ray.cpp

示例11: checkCollision

//============================================================================================
bool Enemy::checkCollision(sf::RectangleShape& playerBounds)
{
    if(boundingBox.getGlobalBounds().intersects(playerBounds.getGlobalBounds())){
       stateChange = true;
       currentState = attack;
    }
    return stateChange;
}
开发者ID:ajmetal,项目名称:2D-platformer,代码行数:9,代码来源:Enemy.cpp

示例12: Collision

//check for collisions
bool Collision(sf::RectangleShape object1, sf::RectangleShape object2)
{

	if (object1.getGlobalBounds().intersects(object2.getGlobalBounds()))
	{

		//if in collision with the second passed object
		return true;

	}
	else
	{

		//if not in collision with the second passed object
		return false;

	}
}
开发者ID:this-jacob,项目名称:MyLittleRPG,代码行数:19,代码来源:Functions.cpp

示例13: handleBallHitsTopOrBottom

void PongGame::handleBallHitsTopOrBottom(sf::RectangleShape &border) {
    sf::FloatRect rectangleBounds = border.getGlobalBounds();
    sf::FloatRect ballRectangleBounds = ball.getGlobalBounds();
    ballSpeed.y = -ballSpeed.y;

    float ballYPosition = 0;
    if (&bottomRectangle == &border) {
        // ball hits bottom rectangle
        ballYPosition = rectangleBounds.top - rectangleBounds.height - ballRectangleBounds.top;
    } else if (&topRectangle == &border) {
        // ball hits top rectangle
        ballYPosition = rectangleBounds.top + rectangleBounds.height - ballRectangleBounds.top;
    }
    ball.move(sf::Vector2f(0, ballSpeed.y + 2 * ballYPosition) * timePerFrame.asSeconds());
}
开发者ID:Yves-T,项目名称:SFML_Pong,代码行数:15,代码来源:PongGame.cpp

示例14: IsSelected

	void IsSelected(Selection s, sf::RenderWindow &Window)
	{
		if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
		{
			if(rect.getGlobalBounds().intersects(s.rect.getGlobalBounds()) || (sf::Mouse::getPosition(Window).x > rect.getPosition().x && sf::Mouse::getPosition(Window).x < rect.getPosition().x + rect.getSize().x && sf::Mouse::getPosition(Window).y > rect.getPosition().y && sf::Mouse::getPosition(Window).y < rect.getPosition().y + rect.getSize().y))
			{
				selected = true;
				rect.setFillColor(sf::Color::Magenta);
			}
			else
			{
				selected = false;
				rect.setFillColor(sf::Color::Green);
			}
		}
	}
开发者ID:Nicholas-Swift,项目名称:Early-Work,代码行数:16,代码来源:Fortress+Survival+Alpha+0.0.4.cpp

示例15: update

	void update(sf::Time timeChange)
	{
		sf::Vector2f p1Movement(0, 0);
		sf::Vector2f p2Movement(0, 0);


		if (p1MovingUp)
			p1Movement.y -= paddleSpeed;
		if (p1MovingDown)
			p1Movement.y += paddleSpeed;
		if (p2MovingUp)
			p2Movement.y -= paddleSpeed;
		if (p2MovingDown)
			p2Movement.y += paddleSpeed;

		p1Paddle.move(p1Movement * timeChange.asSeconds());
		p2Paddle.move(p2Movement * timeChange.asSeconds());


		// Check collision
		if (ball.getPosition().y < 0 || ball.getPosition().y > 480){
			ballMovement.y *= -1;
		}
		if (ball.getGlobalBounds().intersects(p1Paddle.getGlobalBounds()) || ball.getGlobalBounds().intersects(p2Paddle.getGlobalBounds())){
			ballMovement.x *= -1;
		}



		// Scoring
		if (ball.getPosition().x > 600){
			// P1 scores
			ball.setPosition(300, 240);
			p1Score++;
			p1ScoreText.setString(std::to_string(p1Score));
		}
		else if (ball.getPosition().x < 0){
			// P2 scores
			ball.setPosition(300, 240);
			p2Score++;
			p2ScoreText.setString(std::to_string(p2Score));
		}

		ball.move(ballMovement * timeChange.asSeconds());


	}
开发者ID:minhoolee,项目名称:id-Tech-Files,代码行数:47,代码来源:Main.cpp


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