Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Thread Tools Rate Thread Display Modes
Old 05-07-2011, 06:55 PM   #1
Registered User
Join Date: May 2011
Posts: 3
Default Help figuring out how to tell if an object is within a dynamically made circle

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.
nashmage is offline   Reply With Quote
Old 05-08-2011, 01:54 AM   #2
tadster's Avatar
Join Date: Feb 2009
Location: Texas
Posts: 2,111

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.
www.actiontad.com - ActionScript and JavaScript sitting in a tree...
tadster is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 07:30 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.