Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Boundry Boxes on Shapes  (Read 1306 times)

0 Members and 1 Guest are viewing this topic.

marksie

  • Newbie
  • *
  • Posts: 3
    • View Profile
Boundry Boxes on Shapes
« on: June 18, 2016, 10:41:14 am »
Hi all,

Yesterday I download SFML 2.3 and started writing my first pong game. However I am having some issues with Bounding Boxes when it comes to collision detection.

I have been using the tutorials that are provided so far. I can create two paddles and a ball. However the player movable Paddle goes off the screen when in reality I want it to stop. Looking at the bounding box example, I cant see how I would use this with screen coordinates. Any help would be appreciated.

I can see how to look for collisions between object (I think). But the paddle going off the screen is baffling me.

// get the bounding box of the entity
sf::FloatRect boundingBox = entity.getGlobalBounds();

// check collision with a point
sf::Vector2f point = ...;
if (boundingBox.contains(point))
{
    // collision!
}




 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Boundry Boxes on Shapes
« Reply #1 on: June 18, 2016, 01:08:30 pm »
The algorithm is not that complicated, if you take 5 minutes to think about it outside your code.

if (paddle.top < 0)
    paddle.top = 0
else if (paddle.bottom > screen.height)
    paddle.bottom = screen.height

I let you turn this into valid code ;)
Laurent Gomila - SFML developer

 

anything