Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Pixel Collision Function, A must for 2d platformers

Author
Message
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 16th Aug 2010 17:21 Edited at: 16th Aug 2010 17:23
Everyone will agree, the sprite hit and sprite collision commands aren't that useful. So I came up with a function that checks pixel collision. The only drawback with my function is that it only checks pixel collision against the second sprite. This is both good and bad.
The purpose of the function is mainly to check for collision between a player and the level.
To use it just call up PixelCollision.
It will put a bounding box around spr1 and check that box against the pixels of spr2. It returns a string based on where the collision hits. It will return the following
TopL, TopR, BotL, BotR, LefT, LefB, RigT, RigB

This is how they correspond to the sprite


So if the collision occurred on the bottom of the sprite, it would
return BotLBotR
if the collision occurred on the Left side it would return LefTLefB
ect.



My computer can render anything no matter the complexity of it in real time.
The memory is enormous. My computer is unique to everyone else’s. What computer do I have?

Login to post a reply

Server time is: 2026-07-25 09:59:13
Your offset time is: 2026-07-25 09:59:13