Ultrashock Forums > Flash > ActionScript > UltraMath
Target Drop Area

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
Target Drop Area
Old 2009-11-17

Up till now, I've always created a target drop area by using 4 coordinates. My question to you is, in AS2 and/or AS3 is it possible to do the same thing but with radius and the area of a circle? This seems like it could save me a lot of time because there would only be 1 variable. Would this be more taxing on the users computer?
postbit arrow 3 comments | 355 views postbit arrow Reply: with Quote   
Registered User
BSMH is offline
seperator
Posts: 197
2004-07-28
BSMH lives in United States
seperator

Ultrashock Member Comments:
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2009-11-17 #2 Old  
You could use
Code:
public function getBounds(targetCoordinateSpace:DisplayObject):Rectangle
to get the area of the circle. Hopefully that will help you out and is what you were looking for.
Reply With Quote  
BSMH BSMH is offline BSMH lives in United States 2009-11-18 #3 Old  
I'm sorry Isocase. I guess I didn't make what I'm looking for clear.
Rather than typing something like:
Code:
If (mouse.x is <= -32 && mouse.x >= 32 && mouse.y <= -32 && mouse.y >= 32)
I thought there might be a way to dynamically create the same above but with a circle (surrounding an MC) with a set radius. The sole purpose of this circle is (like above) to test if the cursor is inside it to trigger an event. That way I only have to set a radius rather than 4 numbers like the above code. Plus I wouldn't have to keep track of whether a number is negative or positive. Just how wide from the center (radius) I want the circle to be.
Reply With Quote  
BSMH BSMH is offline BSMH lives in United States 2009-11-23 #4 Old  
Well, I had to get my old Trig math book out, but I figured it out. After thinking about it I realize how simple it really is. The mc on the stage is called CenterCirc.

Code:
var radDistance = 5000;

this.onEnterFrame = function() {

	if (distF(CenterCirc)) {
		var cursorDist = Math.round(distF(CenterCirc));

		if (cursorDist<=radDistance) {
			trace("inside circle");
		};
	};

	function distF(CenterCirc):Number {
		return (CenterCirc._x-_xmouse)*(CenterCirc._x-_xmouse)+(CenterCirc._y-_ymouse)*(CenterCirc._y-_ymouse);
	};

};
With this I only have to worry about the radDistance variable. No need to create a perimeter box and calculate negative numbers. I used the Pythagorean theorem to make this work. Essentially this calculates the hypotenuse of a triangle created by the center of the mc and the cursors x y coordinates.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: