SFML community forums

Help => Graphics => Topic started by: Tigre Pablito on July 26, 2013, 06:03:22 am

Title: Collision Method? My Sonic the hedgehog SFML & C#.NET
Post by: Tigre Pablito on July 26, 2013, 06:03:22 am
Hello Dear Ladies and Guys from SFML

Could you tell me if there is any 'Collision function' or method, for example, a function that returns true if two sprites join at some point(s)?
I hope I m not wrong at choosing the Forum (Graphics)

I need this cos at my Sonic game, there are some oblique objects, then I cant test the collision with a square or rectangle

please tell me the function name, and its class, for example:
bool Sprite.Collision(...)   (I already searched and tried this but doesn t exist)

here I give you the aplication, it is still on development
https://www.dropbox.com/s/9ikj1kbm53oqpp3/Sonic%20the%20Hedgehog%20by%20Pablito.rar

Thank you very much in advance

Pablo (Bs As Argentina)
Title: Re: Collision Method? My Sonic the hedgehog SFML & C#.NET
Post by: Gobbles on July 26, 2013, 07:17:24 am
Someone else might have a much better answer then me, but from what I'm getting is you need some form of pixel perfect collision?

If I am mistaken there is a sf::sprite::getGlobalBounds that returns a FloatRect for you to use. If this is the case you could very easily compute a collision with the 2 returned rectangles.

Perhaps a little more info might help here :/ but if you are looking for a specific pixel level collision function, that would almost certainly be something you would have to write up yourself
Title: Re: Collision Method? My Sonic the hedgehog SFML & C#.NET
Post by: fallahn on July 26, 2013, 10:30:13 am
A little while ago I found this (http://info.sonicretro.org/Sonic_Physics_Guide) which explains how all the physics were done in the real sonic games. While it's probably not accurate to use individual pixels as resolutions are so high these days you can create 'collision points' with a vector of sf::Vector2f and use them for testing, along with FloatRect::contains(). I've tried the methods with both a simple platformer and a top down 2D racing game and it works pretty well