Skip to main content
GameDev.net gamedev.net
🔒 Locked

Bitmasks

Started by Zorbfish Jul 18, 2003 at 6:41 PM 1 replies 1k views
Original Post
Zorbfish
Zorbfish
I want to implement bitmask collision detection. Here''s what I have gleaned so far about the process. First when a sprite is loaded a 2d array of 1s and 0s is created by looping through the pixel data looking at every pixel value, where a nonzero value will be represented as a 1. When a collision is tested you find the bounding box overlaps and do a bitmask check at that region. While looping if there ever is a point where both masks have a value of one you have a collision. Now that you know there''s been a collision how should it react? For instance how will you know to move a sprite horizontal or vertical to fix the collision?
Namethatnobodyelsetook
Namethatnobodyelsetook
Per pixel collision is usually overkill, but shouldn''t be too bad since you''re doing bounding box checks first.

How you react to a collision is up to you. There are no set in stone standards. Who says you move horizontally, or vertically? Maybe you lose hitpoints. Maybe you gain a powerup or a life. Maybe you''re pushed back, or maybe the object is pushed.

There are so many possibilities. The collision detection system should just report the collisions, and leave it up to some other part of your app to act on it. That again has possibilities. Does each object know how to deal with collision, or is there a seperate object that resolves collisions between pairs of object types?

Once you''ve gotten that sorted out, then you can deal with how to act on collision. For object runs into wall collisions you''ve still got options. Sometimes you''ll want to backtrack along the direction of movement, for a bullet collision for example. Mario typically stops horizontal or vertical movement depending on how he collides. Jumpman typically moves up until he''s not colliding anymore. Some platform games you can jump up over objects, but cannot fall though them. Some you can jump down through a platform. Some you can''t go up or down through a platform.

The point is, nobody can tell you what to do. Every game is different, or uses different methods depends on context.
Zorbfish
Zorbfish
Yes I''m sorry I was a bit vague. Right now I just finished drawing and making a character move in my tile engine and I really wanted to try a different kind of collision with tiles instead of checking against the tile they are on. That way I could make walls and stuff that were not perfectly square. Part of the reason is that my character has free movement so I want him to move as much as possible.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.