Verge 3 makes pixel-accurate collision detection easy
Displaying 1-5 of 5 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Technetium

The ability of Verge 3 to draw to image buffers other than the screen makes it much easier to create a system for pixel-perfect collision detection than it was in Verge 2. Here's how I am going to do it (and there might be an easier/faster way; I'm not a coding expert).

Suppose you have a sprite with transparent areas, making it unevenly shaped, which is moving around the screen. You want to click on it with the mouse and determine if you successfully clicked within the outline of the image (or suppose you have any situation that calls for determining if a point with known coordinates lies within the image). What I do is create a new image with the dimensions of the sprite you are trying to click on. In that image, rectfill it black. Then use silhouette to blit the sprite in at 0,0 position as solid white (you can actually use any two colors you want). Using the coordinates of the actual sprite as it is located on the screen image, calculate the appropriate position of the mouse relative to the silhouetted image. Then its just a simple matter of using getpixel to determine if the color of the pixel at that point is white or black. If it's white, it's a hit.

You can use a similar method to determine if there is any overlap between two irregularly shapes sprites. Use the silhouette method described above. Then you setlucent(50) and silhouette the 2nd sprite in as black (the same color as the background in that image) over the first in a position relative based upon their proximities on the screen image. Then you do a nested for-loop to scan each pixel of that image. If any pixel is something other than white or black, there is overlap between the two images.

This should run fast enough to keep up with a reasonable framerate, I think.

Posted on 2004-03-18 23:01:02

Gurvy

Your methode sounds great, even if I haven't understand all the meaning of your post :) But I thinks I'll use your trick !!

In a second time, Im not a pure hardcore coder, so I would like to know one thing : When V2 was out, I never knew how that hell autoexec event in system.vc working ? And I see V3 is going to use it arf !!

Bye !
-frenchy gurvy

Posted on 2004-03-18 23:14:00

Omni

As a side note, V2 could draw to image buffer.

Posted on 2004-03-19 01:15:33

Technetium

Really? Wow, that would have helped to know that! :-)

Posted on 2004-03-19 01:28:07

Omni

Yeah. Also, why not just do a GetPixel on the actual sprite and see if it is transparent (255, 0, 255) at a certain location?

Seems kinda overkill to make a lot of buffers just to do a GetPixel.

Posted on 2004-03-19 02:32:40


Displaying 1-5 of 5 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.