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

Author Topic: Rectangle coordinates.  (Read 1428 times)

0 Members and 1 Guest are viewing this topic.

Karsomir

  • Newbie
  • *
  • Posts: 14
    • View Profile
Rectangle coordinates.
« on: August 15, 2013, 02:39:41 pm »
I've recently added simple collision detection for my pong like game. Basically it works like i've got 800x600 frame and im checking if this big frame contains player sprite. Everything is working fine except bottom.
Here's sample code
sf::FloatRect frameBig(0,0,800,600);
        if(!frameBig.contains(sprPlayer.getGlobalBounds().left,sprPlayer.getGlobalBounds().top)
         ||!frameBig.contains(sprPlayer.getGlobalBounds().left+sprPlayer.getGlobalBounds().width,sprPlayer.getGlobalBounds().top)
         ||!frameBig.contains(sprPlayer.getGlobalBounds().left+sprPlayer.getGlobalBounds().width,sprPlayer.getGlobalBounds().top+sprPlayer.getGlobalBounds().height)
         ||!frameBig.contains(sprPlayer.getGlobalBounds().left,sprPlayer.getGlobalBounds().top+sprPlayer.getGlobalBounds().height))

 

So checking top Left, top Right, bottom Right and bottom Left corners of the sprite if they are inside of frame. As I said left,top and right detection works perfectly ( pixel perfect ) but somehow when comming to bottom player sprite stops bit higher like one pixel is missing. Why is there a diffrence?

Here's pic:


Edit:
And the movement is set 1.0f per step.
« Last Edit: August 15, 2013, 03:39:36 pm by Karsomir »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Rectangle coordinates.
« Reply #1 on: August 15, 2013, 02:48:25 pm »
I think you have to -1 bottom (and right?) coordinates.

If your sprite .top is in 700 and its height is 20, its bottom corners pixels y coordinates  will be 719 (700 + 20 - 1) nop?
If your .top was 700 and your .bottom 720 (700 + 20) it would be its height is 21.

Karsomir

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Rectangle coordinates.
« Reply #2 on: August 15, 2013, 02:57:14 pm »
I get it :) Thanks!
« Last Edit: August 15, 2013, 03:03:40 pm by Karsomir »