Discuss Scratch

Viperstryke
Scratcher
18 posts

Mouse Color Sensing

I'm working on a Pen project with a black background and white lines. I want to be able to drag the lines around(which I know how to do) but to do that I need the project to know when the mouse is touching the white lines. Normally I'd use the “If touching mouse” but that wouldn't work, because there are no costumes when you use Pen. Then I tried color sensing; “If color <White> is touching <(the edge of my cursor)White>” but that didn't work. Any suggestions?

Hi, I code Games, MAPS, and Animations. - Viperstryke
DD-8861
Scratcher
100+ posts

Mouse Color Sensing

The simple option would be to make a tiny sprite and have if forever go to mouse pointer. Then you could see if it is touching the color white.

Here is a more complex, yet probably more accurate, option. Say you are drawing the line from point (x1, y1) to point (x2, y2). You could use a bunch of math to calculate the equation of that line. Then plug in the point (mouse x, mouse y) into the equation to see if it is on that line.
Viperstryke
Scratcher
18 posts

Mouse Color Sensing

Thank you so much! That's super helpful. I'll probably go with the mathy option because I'm leader of my coding club this year and I want to make sure my projects don't mess up when I show others

Hi, I code Games, MAPS, and Animations. - Viperstryke

Powered by DjangoBB