1
General / Re: intersection between sprites from different classes
« on: April 23, 2018, 02:00:19 pm »
Hi!
As it is very often the case, the answer to the question is - it depends. More specifically, it depends on the collision body you want to use.
If rectangles are enough for you, it is easy. You can call getGlobalBounds() on your Sprite objects, which returns a rectangle. Then you have two rectangles with which you can call intersects() to check for collisions.
There are other approaches (SAT, pixel-perfect, ...) but this ought to be the easiest one (and usually is enough for axis aligned box collisions).
Also, as a note aside, it is a good programming practice to call your methods with a verb, not noun(s). And you don't have to put rock in front of method names in Rock class, they already are in its namespace. This is not C.
Happy coding
As it is very often the case, the answer to the question is - it depends. More specifically, it depends on the collision body you want to use.
If rectangles are enough for you, it is easy. You can call getGlobalBounds() on your Sprite objects, which returns a rectangle. Then you have two rectangles with which you can call intersects() to check for collisions.
There are other approaches (SAT, pixel-perfect, ...) but this ought to be the easiest one (and usually is enough for axis aligned box collisions).
Also, as a note aside, it is a good programming practice to call your methods with a verb, not noun(s). And you don't have to put rock in front of method names in Rock class, they already are in its namespace. This is not C.
Happy coding
