SFML community forums

General => Feature requests => Topic started by: h2o202 on March 20, 2008, 01:12:41 pm

Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: h2o202 on March 20, 2008, 01:12:41 pm
I would like to have a simple method for collision detection just like shown above.
I know it's better to implement collision detection by myself, but i think collision detection is a often used operation with Sprite's, so why don't implement a method, or more, into the Sprite class?
There could be some different methods with different precisions, like pixelwise, rectangular, ...
I whould like to use this methods while writing my games, and if I see my game works, I can still implement my own collision detection for my specific needs.
What do you think about it?

And execuse my bad school english, I have to work on it :oops:
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: Laurent on March 20, 2008, 01:56:59 pm
I'm thinking about adding some kind of intersection / visibility tests to drawables for next version. Still not sure about details for now.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: h2o202 on March 20, 2008, 03:48:18 pm
OK, thanks for information :D
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: dabo on March 21, 2008, 11:41:00 am
Quote from: "Laurent"
I'm thinking about adding some kind of intersection / visibility tests to drawables for next version. Still not sure about details for now.


Isen't there already one for rectangles, shouldn't that be sufficient?
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: Laurent on March 21, 2008, 04:47:55 pm
Quote
Isen't there already one for rectangles, shouldn't that be sufficient?

No, drawables can be more than an axis-aligned rectangle. They can be rotated, have transparent pixels, have several convex shapes, etc.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: Avency on March 22, 2008, 11:13:29 am
What about using shapes to detect collisions?
And maybe providing a function that generates shapes from the non-transparent part of an image.
Like sf::Shape sf::Sprite::GetCollisionOutline(int Quality), where the quality parameter determines how detailed the shapes end up.
And then use bool sf::Shape::Collide(const sf::Shape& Other) and bool sf::Shape::IsPointInside(int X, int Y).
Shapes are quite flexible and can adapt almost any 2d geometry.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: Laurent on March 22, 2008, 11:33:19 am
How do you build a collision outline from a sprite with random transparent pixels ?

And I think this interface would be too complicated for just simple collision tests.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: Lord Delvin on March 22, 2008, 11:42:56 am
Quote from: "Laurent"
How do you build a collision outline from a sprite with random transparent pixels ?

Forget about the outline I'd say...one could add alpha and check if it's at any point above 1...but that would be an expensive operation.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: dabo on March 22, 2008, 12:40:02 pm
Quote from: "Laurent"
Quote
Isen't there already one for rectangles, shouldn't that be sufficient?

No, drawables can be more than an axis-aligned rectangle. They can be rotated, have transparent pixels, have several convex shapes, etc.
Yea, I guess it depends on what kind of game you are creating.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: Avency on March 22, 2008, 03:09:19 pm
Yep, maybe a function to generate collision outlines might be expensive.
But how to check on collisions between sprites otherwise (if not using just rectangles or pixel perfect collision detection)?
I have no idea...
Collision checking between shapes would still be a nice and useful feature, even if seen independent from the sprite issue.
Though I'm not sure how to implement it.

Quote

And I think this interface would be too complicated for just simple collision tests.

Sure, the implementation is complicated, but the interface itself?
I'm just curious what you are thinking of. :D
I guess I'll have to wait until you are done.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: Laurent on March 23, 2008, 06:02:16 am
I'm still not sure about the interface, I haven't started to implement it.
Title: bool sf::Sprite::CheckCollosion(Sprite param)
Post by: aisman on April 15, 2008, 11:37:42 am
Quote from: "Laurent"
I'm still not sure about the interface, I haven't started to implement it.

Please start ;-)