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.

Code Snippets / Pixel perfect collison for sprites

Author
Message
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 4th Apr 2005 19:56
I have come up with this code for pixel perfect collision



It first checks for a normal sprite collision and then does a bit by bit check on the areas that have collided to see if any pixels have collided.

It could be speeded up by pre loading memblocks with sprite images as the make memblock from image takes a little time. When I tested preloading the images the overhead was negligable. As it is the slowdown is not too bad.

Any comments/Questions are welcome.

Cloggy
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 5th Apr 2005 01:58
Update do png transparency and BMP collision.



The transparent areas must be 100% transparent or they will be detected as normal pixels for collision.
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 5th Apr 2005 05:10
Don't want to appear pushy, but could somebody test this with 32-bit alpha transparency png images as sprites.

1nteger has tried but it doesn't work for him. Works here. I have U5.8

Cheers,

Cloggy
Lampton Worm
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 5th Apr 2005 05:45
Hi,

Looks good, can you post your .png files please?

Cheers.
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 5th Apr 2005 05:49
Sorry, Here are the png files.

Cloggy

Attachments

Login to view attachments
Lampton Worm
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 6th Apr 2005 18:04
Hi,

It told me that the zip was invalid or corrupted?

Cheers.
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 7th Apr 2005 06:19
I'll try attaching again. Re zipped on a different PC.

Cloggy

Attachments

Login to view attachments
Lampton Worm
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United Kingdom
Posted: 10th Apr 2005 20:15
Thanks, works great, good stuff
Baggers
20
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 10th Apr 2005 23:32 Edited at: 10th Apr 2005 23:32
Very nice work there Cloggy !
Ill keep hold of this snippet.
Ken Tankerous
20
Years of Service
User Offline
Joined: 31st Mar 2005
Location:
Posted: 12th Apr 2005 13:17
Works great. Very nice stuff there.

Ken
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 12th Apr 2005 20:24
does this support rotated/scaled sprites?

[07:16:59-pm] « Sephnroth » you were dreaming about lee...
[07:17:13-pm] « Mouse » stfu
[07:17:22-pm] « Mouse » he was hanging himself lol
Cloggy
20
Years of Service
User Offline
Joined: 31st Oct 2004
Location: Rayleigh, Essex
Posted: 12th Apr 2005 21:17
Unfortunately not. It uses the sprite image for the collision test and when you rotate/scale a sprite the image does not change. This is because the sprites are made using 3d plains.

Not sure if I can do anything with this. I'll have a look.

Cloggy
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 14th Apr 2005 01:33
if you manage to get it going with rotation and stuff somehow I will be infinatly happy ^^ Not many people have a set of sprites that stay always facing the same way :/

[07:16:59-pm] « Sephnroth » you were dreaming about lee...
[07:17:13-pm] « Mouse » stfu
[07:17:22-pm] « Mouse » he was hanging himself lol

Login to post a reply

Server time is: 2025-05-18 22:07:27
Your offset time is: 2025-05-18 22:07:27