Sign in to follow this  
dAND3h

Collision Mask SDL

Recommended Posts

dAND3h    220
Hey, I am looking to implement some collision detection for my 2d "engine". I came across collision masks while googling. It seems like a really good idea, the problem is, I do not fully understand how to make/implement it. This is what I understand so far:
1. I create my level using paint or whatever.
2. Then what I do is create a new layer, and draw for example, a straight black rectangle over the ground. I then delete the original level layer so I am just left with the black rectangle.
3. Load the map and mask into separate SDL_Surfaces.

But after this is where I do not understand what to do! I have some questions that I would be grateful for an answers:
1. How do I actually test the collision?
2. Do I have to iterate through each pixel in the mask and then check the colour of the pixel?
3. How do I set a different type of collision on a different colour?(I'm guessing I just do some check like: if(pixel is black) COLLISION_TYPE = ground)...but that seems wrong?
4. Do I have to iterate through the entire mask every time through my game loop? Which would mean iterating through each pixel?
5. How would I apply a mask to a moving surface, such as my player character?

I am sorry for being so noob but this is really hard to understand. Please can somebody try to answer these questions. Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this