[Flashcoders] Detecting if line crosses movie clip
Working on a game where the player must draw around some colored balls on screen by dragging the mouse to create the polygon that surrounds the objects. The polygon is created by drawing a series of lines every time the mouse moves. If one of these lines intersects one of the balls (movie clip) I need to perform an action. So my question is how to detect when the line intersects a movie clip? The following is unsuitable as it treats the line as a rectangle e.g a vertical line will have a lot of hit area that I do not want to be hit area if (ballMC.hitTestObject(lineMC)) { My other best suggestion is to use the 4 lines that make up the bounding box of the ball movie clip and do a line intersection test for each line against the line being drawn. This seems overly complex so before I try this I wanted to check there is not a simpler solution. Thanks in advance ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Detecting if line crosses movie clip
On 16/06/2011 13:58, Paul Steven wrote: Working on a game where the player must draw around some colored balls on screen by dragging the mouse to create the polygon that surrounds the objects. The polygon is created by drawing a series of lines every time the mouse moves. If one of these lines intersects one of the balls (movie clip) I need to perform an action. So my question is how to detect when the line intersects a movie clip? The following is unsuitable as it treats the line as a rectangle e.g a vertical line will have a lot of hit area that I do not want to be hit area if (ballMC.hitTestObject(lineMC)) { My other best suggestion is to use the 4 lines that make up the bounding box of the ball movie clip and do a line intersection test for each line against the line being drawn. This seems overly complex so before I try this I wanted to check there is not a simpler solution. http://keith-hair.net/blog/2008/08/05/line-to-circle-intersection-data/ Thanks in advance ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Detecting if line crosses movie clip
Hi, Can you measure the vector distance between the centre of the polygon and the centre of the ball? If that is 0,0, and the diameter of the circle is less than the smallest of width / height of the box, then you are inside. Glen On 16/06/2011 13:58, Paul Steven wrote: Working on a game where the player must draw around some colored balls on screen by dragging the mouse to create the polygon that surrounds the objects. The polygon is created by drawing a series of lines every time the mouse moves. If one of these lines intersects one of the balls (movie clip) I need to perform an action. So my question is how to detect when the line intersects a movie clip? The following is unsuitable as it treats the line as a rectangle e.g a vertical line will have a lot of hit area that I do not want to be hit area if (ballMC.hitTestObject(lineMC)) { My other best suggestion is to use the 4 lines that make up the bounding box of the ball movie clip and do a line intersection test for each line against the line being drawn. This seems overly complex so before I try this I wanted to check there is not a simpler solution. Thanks in advance ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ca ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Detecting if line crosses movie clip
Thanks Paul - that looks awesome and just what I need -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Paul Andrews Sent: 16 June 2011 14:48 To: Flash Coders List Subject: Re: [Flashcoders] Detecting if line crosses movie clip On 16/06/2011 13:58, Paul Steven wrote: Working on a game where the player must draw around some colored balls on screen by dragging the mouse to create the polygon that surrounds the objects. The polygon is created by drawing a series of lines every time the mouse moves. If one of these lines intersects one of the balls (movie clip) I need to perform an action. So my question is how to detect when the line intersects a movie clip? The following is unsuitable as it treats the line as a rectangle e.g a vertical line will have a lot of hit area that I do not want to be hit area if (ballMC.hitTestObject(lineMC)) { My other best suggestion is to use the 4 lines that make up the bounding box of the ball movie clip and do a line intersection test for each line against the line being drawn. This seems overly complex so before I try this I wanted to check there is not a simpler solution. http://keith-hair.net/blog/2008/08/05/line-to-circle-intersection-data/ Thanks in advance ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Detecting if line crosses movie clip
Thanks Glen - this sounds like another good solution. I assume this would work when the polygon is just a single line? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike Sent: 16 June 2011 14:48 To: Flash Coders List Subject: Re: [Flashcoders] Detecting if line crosses movie clip Hi, Can you measure the vector distance between the centre of the polygon and the centre of the ball? If that is 0,0, and the diameter of the circle is less than the smallest of width / height of the box, then you are inside. Glen On 16/06/2011 13:58, Paul Steven wrote: Working on a game where the player must draw around some colored balls on screen by dragging the mouse to create the polygon that surrounds the objects. The polygon is created by drawing a series of lines every time the mouse moves. If one of these lines intersects one of the balls (movie clip) I need to perform an action. So my question is how to detect when the line intersects a movie clip? The following is unsuitable as it treats the line as a rectangle e.g a vertical line will have a lot of hit area that I do not want to be hit area if (ballMC.hitTestObject(lineMC)) { My other best suggestion is to use the 4 lines that make up the bounding box of the ball movie clip and do a line intersection test for each line against the line being drawn. This seems overly complex so before I try this I wanted to check there is not a simpler solution. Thanks in advance ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ca ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Detecting if line crosses movie clip
I am not sure - do you mean single line like a circle, or a single line as in straight one? My idea was to test if a circle was inside a rectangle, so not sure if would work with single lines... It might not work very well with anything but a rectangle either. On 16/06/2011 15:09, Paul Steven wrote: Thanks Glen - this sounds like another good solution. I assume this would work when the polygon is just a single line? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike Sent: 16 June 2011 14:48 To: Flash Coders List Subject: Re: [Flashcoders] Detecting if line crosses movie clip Hi, Can you measure the vector distance between the centre of the polygon and the centre of the ball? If that is 0,0, and the diameter of the circle is less than the smallest of width / height of the box, then you are inside. Glen On 16/06/2011 13:58, Paul Steven wrote: Working on a game where the player must draw around some colored balls on screen by dragging the mouse to create the polygon that surrounds the objects. The polygon is created by drawing a series of lines every time the mouse moves. If one of these lines intersects one of the balls (movie clip) I need to perform an action. So my question is how to detect when the line intersects a movie clip? The following is unsuitable as it treats the line as a rectangle e.g a vertical line will have a lot of hit area that I do not want to be hit area if (ballMC.hitTestObject(lineMC)) { My other best suggestion is to use the 4 lines that make up the bounding box of the ball movie clip and do a line intersection test for each line against the line being drawn. This seems overly complex so before I try this I wanted to check there is not a simpler solution. Thanks in advance ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ca ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] Detecting if line crosses movie clip
I did mean a single straight line so it probably wouldn't have worked. Fear not as the code that Paul pointed me to works a treat. Thanks for the super fast replies -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike Sent: 16 June 2011 15:26 To: Flash Coders List Subject: Re: [Flashcoders] Detecting if line crosses movie clip I am not sure - do you mean single line like a circle, or a single line as in straight one? My idea was to test if a circle was inside a rectangle, so not sure if would work with single lines... It might not work very well with anything but a rectangle either. On 16/06/2011 15:09, Paul Steven wrote: Thanks Glen - this sounds like another good solution. I assume this would work when the polygon is just a single line? -Original Message- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Glen Pike Sent: 16 June 2011 14:48 To: Flash Coders List Subject: Re: [Flashcoders] Detecting if line crosses movie clip Hi, Can you measure the vector distance between the centre of the polygon and the centre of the ball? If that is 0,0, and the diameter of the circle is less than the smallest of width / height of the box, then you are inside. Glen On 16/06/2011 13:58, Paul Steven wrote: Working on a game where the player must draw around some colored balls on screen by dragging the mouse to create the polygon that surrounds the objects. The polygon is created by drawing a series of lines every time the mouse moves. If one of these lines intersects one of the balls (movie clip) I need to perform an action. So my question is how to detect when the line intersects a movie clip? The following is unsuitable as it treats the line as a rectangle e.g a vertical line will have a lot of hit area that I do not want to be hit area if (ballMC.hitTestObject(lineMC)) { My other best suggestion is to use the 4 lines that make up the bounding box of the ball movie clip and do a line intersection test for each line against the line being drawn. This seems overly complex so before I try this I wanted to check there is not a simpler solution. Thanks in advance ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ca ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] Detecting if line crosses movie clip
Glen Pike skriver: Hi, Can you measure the vector distance between the centre of the polygon and the centre of the ball? If that is 0,0, and the diameter of the circle is less than the smallest of width / height of the box, then you are inside. Glen Not in all cases: http://img694.imageshack.us/img694/8197/horseshoeq.png ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders