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

Author Topic: Collision Detection Problems and freezes with sprites etc  (Read 1749 times)

0 Members and 1 Guest are viewing this topic.

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Collision Detection Problems and freezes with sprites etc
« on: August 08, 2011, 06:02:47 am »
Hi, I've developed somewhat a basic little pong like ball that has to stay within certain boundaries. When dealing with a sf::shape, it doesn't have any type of bugs or errors. While using the same code as the sf::shape, if I switch it to sf::sprite with an image acting as the ball, it will freeze and be very buggy going through the boundaries set.

I'm wondering why is this? Is sf::sprite more intense and need to be implemented some other way. Should I add extra catching boundaries or possibly(just thought of now) have a exception like clause that will redraw and reimplement the ball on messing up exactly where it was last within the boundaries??

vro

  • Newbie
  • *
  • Posts: 44
    • View Profile
Collision Detection Problems and freezes with sprites etc
« Reply #1 on: August 08, 2011, 10:07:16 am »
It might help to show your code.

Remember to set the center of the sprite, such as: Ball.setCenter(Ball.getSize() / 2.f)

That might be why it appears buggy, since by default the center of the sprite is the top left corner.

That's just an idea

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Collision Detection Problems and freezes with sprites etc
« Reply #2 on: August 08, 2011, 11:46:24 am »
That actually might be why. I never set the center of any sprites. I just sf::Sprite::SetPosition().

Could you give me a more in depth explanation of why this is needed? I really want to understand this. Idk I probably took 30 seconds to think about why this didn't work and my answers were completely different than sf::Sprite::SetCenter().

Also possibly how Sprites are loaded and about them etc.

Thanks

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Collision Detection Problems and freezes with sprites etc
« Reply #3 on: August 09, 2011, 09:27:59 pm »
Hey, I was actually thinking... lol thinking.... you say that I need to use sf::Sprite::SetCenter... Why would that matter dependent on if it was sf::Shape or sf::Sprite. Shouldn't they be the same and it be totally independent on those two classes. As in since the code worked for sf::Shape then why would sf::Sprite not work and need sf::Sprite::SetCenter()?? Yup just checked... sf::Shape has a sf::Shape::SetCenter() function as well.

KasHKoW

  • Newbie
  • *
  • Posts: 41
    • View Profile
Collision Detection Problems and freezes with sprites etc
« Reply #4 on: August 09, 2011, 09:28:07 pm »
Hey, I was actually thinking... lol thinking.... you say that I need to use sf::Sprite::SetCenter... Why would that matter dependent on if it was sf::Shape or sf::Sprite. Shouldn't they be the same and it be totally independent on those two classes. As in since the code worked for sf::Shape then why would sf::Sprite not work and need sf::Sprite::SetCenter()?? Yup just checked... sf::Shape has a sf::Shape::SetCenter() function as well.

 

anything