本文整理汇总了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));
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例11: checkCollision
//============================================================================================
bool Enemy::checkCollision(sf::RectangleShape& playerBounds)
{
if(boundingBox.getGlobalBounds().intersects(playerBounds.getGlobalBounds())){
stateChange = true;
currentState = attack;
}
return stateChange;
}
示例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;
}
}
示例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());
}
示例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);
}
}
}
示例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());
}