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

Author Topic: Sprite movement help  (Read 1832 times)

0 Members and 1 Guest are viewing this topic.

OrientatedCookie

  • Newbie
  • *
  • Posts: 18
    • View Profile
Sprite movement help
« on: April 17, 2015, 03:53:44 pm »
I'm currently making a classic ping pong game, but I don't know what the code/syntax is for if a sprite contacts another sprite, if you know what I mean. I thought I could make an if statement that checks if the ball is touching the rectangle or something like that, and then make it go towards somewhere.  Can anyone help me with this, or what other way could I do it?  :D

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Sprite movement help
« Reply #1 on: April 17, 2015, 04:50:56 pm »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

OrientatedCookie

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Sprite movement help
« Reply #2 on: April 17, 2015, 05:09:08 pm »
You could of just written it in text, not with the slightly overdone derision.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Sprite movement help
« Reply #3 on: April 17, 2015, 06:02:45 pm »
Or you could just have searched for it. It's not like it's the most complicated things and you're the first to ask this. There is thousands of post on the web about this. Follow the link from zsbzsb, and you'll find an answer for sure.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Sprite movement help
« Reply #4 on: April 17, 2015, 06:24:08 pm »
Chances are that your problem was already solved somewhere on the internet, so after checking the documentation, don't hesitate to:
  • search the SFML forum
  • ask Google

Collision detection is a huge topic, hence the link. When you ask "how to do collision detection" its not something that we can just explain. So unless you are more specific on what you need help with pretty much all you will get is very generalized answers.

On a side note, collision detection and response (physics in general) is really more of a math question than a graphics question. Graphics are displayed on top of what your physics code does when it actually updates your objects positions and whatnot.

sf::Rect<T>::intersects(...)
« Last Edit: April 17, 2015, 06:26:45 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Sprite movement help
« Reply #5 on: April 17, 2015, 06:32:03 pm »
I've always found the following article very useful as a basic starting point: Pool Hall Lessons: Fast, Accurate Collision Detection Between Circles or Spheres.
 Maybe you'll enjoy it as well.

Also, this is a good book that's relevant to physics simulation and collision detection that I'd recommend reading : Physics for Game Developers, 2nd Edition.

As has already been pointed out, collision detection is a huge topic and it's really not within the scope of SFML. SFML just lets you draw stuff and test basic things like if rectangles intersect, but if you want to use bounding boxes (axis alligned or not), bounding spheres, pixel perfect collision detection or something else, then it's really into the math/physics domain and you have to do your own calculations. SFML will draw the results of your calculations nicely for you (but it won't do the detection work).
« Last Edit: April 17, 2015, 07:16:57 pm by Jesper Juhl »