View Full Version : Help figuring out how to tell if an object is within a dynamically made circle

05-07-2011, 06:55 PM
Hello Everyone,

I am currently in the middle of working on a project but sadly I am having a bit of trouble getting a few things figured out.

Essentially what the project consists of is I have random balls appearing on the screen and moving around and I need to make it so that the user is able to draw a circle around the ball (may be more than one) and have that balls dissapear and count the number of balls circled.

This project is being done in flash builder 4.5 and is being made for the android platform as part of a senior project.

At this point this is where I am.. I have been able to randomly create the balls and give them a random movement. I have also been able to figure out how to allow the user to draw on the screen.

What I am trying to figure out is how to make it so that if the user draws a circle around the balls make it so that I know these balls have been circled and make them dissapear and have the number of balls inside the area calculated.

I have thought about making the entire background a grid and make it so that I can track somehow the line made by the user and then track the coordinate of the balls then if it is within that area it means that the ball has been circled but I would like something more efficient than that.

I apologize if it is unclear for what I am looking for but a simple description is I am making a simple game where you are able to circle a moving item on screen, then once it is circled the item disappearsand you gain a point.

Any help would be greatly appreciated.

05-08-2011, 01:54 AM
It should not be too hard if you use pixel perfect collision detection.
After the user has drawn the circle, fill it in* with a mostly transparent color, and use that fill space to pixel perfectly hit detect amongst the balls, all the balls that are hitting the area, are inside the circle.

*easier said than done, since the user draws the circle.
But, I think it should be easy to just make sure that whatever the user draws into has no width or height to begin with, so what they draw determines the width and height, then just fill that area transparently and hit test against it.

Troy Gilbert made a really nice pixel perfect algorithm that's just one function.
Also there is the Collision Detection Kit by Corey Oneal, in fact it has an example where you can draw the terrain that a ball will land/roll on, you may like seeing that, but I think that may be too intense for phones.