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.

Game Design Theory / Pixel-Perfect Collision

Author
Message
RUCCUS
20
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 9th Aug 2006 03:48
Had a quick idear', I've heard that DBP has yet to have PP Collision (other than with the use of an extension like Extends or something), so this might work;

Convert the image/sprite/whatever into a memblock, get the 2d positinos of all of the pixels that aren't the mask colour. Using these coordinates, make a 3D model, placing vertexe's at each 2D coordinate. This'll give you a flat, plain-like model in the shape of the sprite, now add te same vertices but lower on the y axis, and connect all of the verts to have a sort of 3D model of the sprite. Now use the 3D collision commands (intersect object namely) and you'll be able to detect perfect collisions. Always orient the 3D model to the camera to apear 2D, and... done.

Anyways I havent used the memblock commands so I wouldn't know where to start, just throwin it out there, might be a cool function.


Projects: Online CTF Game | Newcommer's Guide to FPS's
Jack LOL
19
Years of Service
User Offline
Joined: 4th Aug 2006
Location: Near the CPU Close to the graphic card
Posted: 26th Aug 2006 13:31
So u r talking about converting the image/sprite to a 3d object and use the 3d collision command?

lol?! xD
Cash Curtis II
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 26th Aug 2006 18:59 Edited at: 26th Aug 2006 19:01
Or you could do this...



This works nicely, and is pretty fast.

I do see what you're talking about though. The answer is vector collision, like PlayBasic does. Basically, you define the shape of the collidable as a vector image, or a collection of points relative to the shape of the sprite that define the vector.

Collision is as perfect as the vector image (which is 99% perfect if you do it right), scalable, can rotate, and is extremely fast. Someone should write a vector collision plugin for DBP rather than pixel perfect collision, because this is too easy, as in the example above.

That code works with transparent PNGs. If the opacity of a pixel is 0, it is not counted.


Come see the WIP!
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 27th Aug 2006 08:24
While that'd work, it's not really very efficient way of doing it. However for the record, PlayBasic doesn't just include vector modes. It also has a inter sprite Pixel Perfect collision modes, incorporating scalable accuracy which are interchangeable with vector modes. ATM PB has 7 main sprite collisions from box, rotated, circular, shape, sliding, sticky and pixel. All of which can be combined. SO vector shape can impact a pixel mode sprite. or you can detect if a ray hits a sprites pixels etc..

Jack LOL
19
Years of Service
User Offline
Joined: 4th Aug 2006
Location: Near the CPU Close to the graphic card
Posted: 28th Aug 2006 01:27
Cash Curtis II:
TTTTTTTTTTTHHHHHHHHHHAAAAAAAAAAANNNNNNNNNKKKKKKKSSSSSSSSSS
MAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
U JUST SOLVED THE MILLENIUM PROBLEM AND SAVED THE eXtends MONEY!!!!!!!!!!!
I'm the happyest man in the world and its all thanks to YOU!!!!!!!

lol?! xD
Cash Curtis II
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 29th Aug 2006 15:15
@Jack LOL -
Well, I'm glad that code is useful to you. eXtends is a great set of plugins, much more then just pixel perfect collision. It also allows you to test for collisions on rotated sprites, which this code does not.

@Kevin Picone -
That is some really intersting information. A plugin that provides similar functionality for DBP could certainly be written. Thanks!


Come see the WIP!
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 29th Aug 2006 17:59
Jack LOL
19
Years of Service
User Offline
Joined: 4th Aug 2006
Location: Near the CPU Close to the graphic card
Posted: 29th Aug 2006 21:24
Its not a problem to test collision on rotated sprites cuz what u can do is just to rotate the sprite and get its rotated image with the "get image" command and do your PPcol on it and it will work right?

lol?! xD
Cash Curtis II
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 29th Aug 2006 22:03 Edited at: 29th Aug 2006 22:07
Yeah, but doing that every loop is extremely slow.

Quote: "Good luck, you'll need it "




Come see the WIP!
2D Analyst
AGK Developer
21
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 23rd Oct 2006 22:53
Hm...I was planning to buy the extends expansion pack too for the pixel collision..guess I'll try out Cash Curtis collision code first...

www.simpoware.com
2D Analyst
AGK Developer
21
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 24th Oct 2006 01:49
I remember I used that function before and it works fine..but not sure why it's not working now? Could it be because it has something to do with the latest patch?

www.simpoware.com
Cash Curtis II
20
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 24th Oct 2006 04:46
Post the image that you're checking collision against and I might be able to tell you more.


Come see the WIP!

Login to post a reply

Server time is: 2025-08-08 16:30:53
Your offset time is: 2025-08-08 16:30:53