# Finding the nearest collision point distance, Pixel count

#### Geners

##### Member
Is there a way I can find the NEAREST point of collision between two objects or a point and an object. For the life of me I can't figure out how I would go about doing this, I thought up multiple solutions but all of them are really tedious and slow on processing.

Also is there a way I can get the total non-alpha pixels in a sprite with GML code? Would I need to use a shader to loop through each pixel?

I was thinking about maybe using a collision line to check in each direction and whichever collision was the shortest distance using that but this method isn't super accurate and I can imagine being very inefficient.

Last edited:

#### flyingsaucerinvasion

##### Member
You won't be able to use a shader to count pixels of a certain color or alpha. It could be done using a surface. But why do you need to know the number of non-alpha-pixels?

The "nearest" point of collision could be interpreted in different ways. Can you give a specific example?

#### Geners

##### Member
You won't be able to use a shader to count pixels of a certain color or alpha. It could be done using a surface. But why do you need to know the number of non-alpha-pixels?

The "nearest" point of collision could be interpreted in different ways. Can you give a specific example?
I need the total non-alpha pixels because the player is going to try and trace over a line given each round, I need to know how many pixels there are so I can see how much surface of the line was covered and how much is left on any given thing that needs to be traced (always black lines, sometimes oriented into shapes) I'm going to do this by checking if each point of the brush (a stroke being made up by little black circles) has collided with the line, the closer the stroke was to the line the more points they get.

For example, where the closest point between the players brush and a line. (The line having a precise collision mask)

#### Geners

##### Member
I guess I could also just add collision "Point" objects to each drawing sprite and just place them along the lines and every time they hit a point their score rises but then I'm scared they could just figure out where the points are and just dot each point with the brush.

Last edited: