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

Author Topic: Should Sprite Alpha affect collision detection?  (Read 2078 times)

0 Members and 1 Guest are viewing this topic.

shaidyn

  • Newbie
  • *
  • Posts: 5
    • View Profile
Should Sprite Alpha affect collision detection?
« on: April 18, 2013, 08:09:42 pm »
Hi folks! I'm very new to SFML, and this is my first time posting. If I'm asking a stupid question in the wrong place, let me know and I'll do my best to fix it.

So, I've implemented the simple collision detection module (http://www.sfml-dev.org/wiki/en/sources/simple_collision_detection), and it works just fine. I have a number of sprites for walls, and a sprite for the player, and when the player walks into the wall he stops. No problems there.

I decided I wanted to make a transparent sprites with collision. These would represent traps on the floor that the player can't see. I used .SetColor to set the alpha for the sprite down to 0, making it transparent. But for some reason that I can't figure out, this removed all collision detection. In fact, any alpha value below  128 removes collision detection.

I can't for the life of me figure out why. The alpha doesn't make any changes to the 'math' behind the detection. It's purely visual. Is there something I'm missing?

The code I'm using to change alpha is:

wall_left->set_colour(255,255,255,128);

Which feeds into:

void VisibleGameObject::set_colour(float red, float blue, float green, float alpha)
{
   _sprite.SetColor(sf::Color(red, blue, green, alpha));
}

Nothing exciting, but I figure I should post it for completeness.

foobarbaz

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Should Sprite Alpha affect collision detection?
« Reply #1 on: April 19, 2013, 08:10:13 am »
Which collision detection are you using? Circle? Bounding box? Pixel perfect?

shaidyn

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Should Sprite Alpha affect collision detection?
« Reply #2 on: April 19, 2013, 06:11:47 pm »
I'm using Pixel perfect

foobarbaz

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Should Sprite Alpha affect collision detection?
« Reply #3 on: April 19, 2013, 08:35:22 pm »
What are you setting as your AlphaLimit parameter? By glancing at that Collision code from the link you provided , it looks like only alpha values above that alpha limit will trigger a collision. So, if you want anything even remotely visible to collide, your AlphaLimit should be 1 :)