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

Author Topic: How to implement per-pixel collision and how to cut the pixels from sprite?  (Read 1411 times)

0 Members and 1 Guest are viewing this topic.

Christ00pher

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
Hello there,

I'm currently writing a game which involves shooting (Space Invaders-like game). Now I'm trying to figure out how to implement the shield mechanism.
I thought that firstly I might use the regular box collision and check if any of the bullets intersects the bounding box of the shield, then I wanted to use per-pixel collision (knowing the bullet is in a bounding-box area would cut unnecessary checks between the bullets which are far away from the shield).
What I want to achieve is when the bullet hits the shield, a part of the shield in size of the bullet is cut off from the sprite and obviously this area "doesn't belong" to the shield anymore - the collision on cut-off pixels is not checked.
Is there any way to do it in SFML? I found sf::Image class and it's method: void sf::Image::setPixel(...), but I'm not sure if it will work though.
What's more, I have no idea how to implement the per-pixel collision.

Greetings!

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
You don't explain your problem very well besides asking for code. If you want pixel sized collision, use pixel sized colliders.