SFML community forums
General => General discussions => Topic started by: lruc on August 19, 2008, 02:57:59 am
-
Is there anyway to detect sprite collisions in SFML? I wanted to use SFML to make a simple RPG but it doesn't have a lot of things that I thought it would have, mostly sprite collision. Is SFML even meant for games?
-
You can create your own collision detection with SFML.
All you need to detect collisions in any situation is the position and size of the objects.
With SFML's graphic package, all sprites already have a position and a rectangular shape.
To imagine this, here is a little ascii art of a rectangle with the calculations to get all four points of the rectangle:
(x, y)-----------------------(x + width, y)
| |
| |
| |
| |
| |
(x, y + height)-----(x + width, y + height)
Using the greater than and less than operators, you can easily see if one sprite's rectangle is overlapping another's.
This should suffice for a simple 2D RPG.
Study into collision detection a bit more though and using the same concepts you can create pixel perfect collision detection in SFML.
-
How about something like animation support? ex. like GIF's of bmp sprite sheets.
-
Edit: GIF's OR bmp sprite sheets
-
Edit: GIF's OR bmp sprite sheets
You can do that pretty easily by setting the subrect of the image.
-
I think that some kind of scene partition management should be used in order to eliminate each-to-each collision testing. :)
-
if you're able to sort your boxes along the X axis you could use some line swep algo for doing collision test... might be easyier to maintain a sorting along X-axis in a moving scene than maintaining a komplete Quadtree or something like this....
though quadtree would most likely be faster...
-
if you're able to sort your boxes along the X axis you could use some line swep algo for doing collision test... might be easyier to maintain a sorting along X-axis in a moving scene than maintaining a komplete Quadtree or something like this....
though quadtree would most likely be faster...
I posted a bit on this before:
http://www.sfml-dev.org/forum/viewtopic.php?t=524&highlight=collision+detection