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

Author Topic: Collision Method? My Sonic the hedgehog SFML & C#.NET  (Read 2626 times)

0 Members and 1 Guest are viewing this topic.

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Collision Method? My Sonic the hedgehog SFML & C#.NET
« 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)

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Collision Method? My Sonic the hedgehog SFML & C#.NET
« Reply #1 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

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: Collision Method? My Sonic the hedgehog SFML & C#.NET
« Reply #2 on: July 26, 2013, 10:30:13 am »
A little while ago I found this 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