Collision help! (possibly image-heavy)

BlitzMax Forums/BlitzMax Programming/Collision help! (possibly image-heavy)

Ked(Posted 2009) [#1]
Alright. So, I have two images. One image is the background:

(white is the walls, black is the floor)

One is the player/object:

(white is the player/object, black is the mask)

I am using the ImagesCollide2() function as my collision function. My problem is that the player/object always seems to get "hooked" onto the background:


I would like for it to not do this. Is there anyway I can get collision detection like this?:


Thanks in advance!


_Skully(Posted 2009) [#2]
Test with a different image that has no mask


_JIM(Posted 2009) [#3]

Test with a different image that has no mask



Or make your specific function. You can optimize it a lot more than ImagesCollide2. Like pick 4 pixels (corners) from the level image. If any of them is a white pixel, then you have collision. If not, then check the 4 lines. Unless the movement is too fast and you have section that are too small into the level (so that a small piece can be "outside" of the player bounding box and the next frame it's 100% inside), then this should cover all your collision needs. :)


Brucey(Posted 2009) [#4]
Aren't bounding box tests quicker anyway?


_JIM(Posted 2009) [#5]

Aren't bounding box tests quicker anyway?



I was thinking maybe his level has weird shapes, but the player is checked like a bounding box. Like a hybrid :-)


Ked(Posted 2009) [#6]
Thanks everyone for your help! I decided to go with suggestion number one though:
Test with a different image that has no mask

All of my map tiles are square. The only weird-shaped tile is the player.


_JIM(Posted 2009) [#7]

All of my map tiles are square. The only weird-shaped tile is the player.



Then Brucey's suggestion is actually the best performance-wise: AABBs (Axis-Aligned Bounding Box)


ImaginaryHuman(Posted 2009) [#8]
Give your player image an alpha channel and alphablend it rather than maskblend?


Ked(Posted 2009) [#9]
Give your player image an alpha channel and alphablend it rather than maskblend?

I always give alpha channels and use alphablend. The "error" is still there. But it's fixed now with _Skully's suggestion.