0

my goal is to make a simple follow-the-line type of game in Javascript. I know nothing of javascript, but I know programming (Java mainly).

In this game, user has to follow a drawn line with his/her mouse pointer. There is start and end point of line, naturally.

So far I found this code: Make an image follow mouse pointer, but now I'm struggling with checking when mouse coordinates are not inside of line.

I can use any library, so if there are some easy js libraries for games, please recommend them to me.

So, to repeat the question: how do I check if mouse cursor is inside of line (pipe)? If you have any additional advice, please post it.

Community
  • 1
  • 1
user3007875
  • 123
  • 7

1 Answers1

0

There's a few ways to look at this problem. Arguably the easiest would be to create the "pipes" using SVG paths, and then detecting if the mouse was hovering over these lines.

<svg>
   <path ...>
</svg>

$("svg path").hover(function () {
   // I'm inside the line!
}, function () {
   // I left the line!
});

This uses a library called jQuery by the way, which I'm going to assume you're using based on your image follow example.

Jack Guy
  • 8,346
  • 8
  • 55
  • 86
  • I know nothing of jQuery (except that it's made to make javascript easier), but I will try using SVG paths, as you recommend. Thank for the answer. – user3007875 Nov 10 '15 at 22:11