Hope someone can put me out of misery here.
I have attached a .zip file that contains the fla/swf/.as files that make my movie work. There are are two obstacle mc's and one cursor mc. The cursor mc stops at the border of the two obstacle mc's
Here is what I am trying to do - I need to make the cursor mc follow the irregular shaped borders of the obstacle mc's - at the moment the cursor mc stops at the border of the whole mc (bounding box of the clip) and doesn't follow the curves etc...
How do I change the code to recognise the irregular shapes? and also to follow the real cursor as it moves around inside the obstacle mc's?
This is the script that makes the cursor stop at the mc borders etc...
PHP Code:
class CursorManager
{
private var obstacleList:Array;
private var cursor:MovieClip;
public function CursorManager(cursorClip:MovieClip)
{
cursor = cursorClip;
obstacleList = new Array();
}
public function addObstacle(obstacle:MovieClip):Void
{
obstacleList.push(obstacle);
}
public function updateCursorPosition():Void
{
var mouseX:Number = _level0._xmouse;
var mouseY:Number = _level0._ymouse;
// Default to mouse position.
cursor._x = mouseX;
cursor._y = mouseY;
// Move the cursor if it is inside an obstacle.
for (var i:Number = 0; i < obstacleList.length; i++)
{
// Assumes that the obstacles are children of _level0.
// Might need to use the Rectagle classes intersection function to
// determine if the cursor is intersecting.
if (obstacleList[i].hitTest(mouseX, mouseY))
{
moveCursorOutsideObstacle(obstacleList[i], mouseX, mouseY);
break;
}
}
}
public function moveCursorOutsideObstacle(obstacle:MovieClip, mouseX:Number, mouseY:Number):Void
{
var xPos:Number = mouseX;
var yPos:Number = mouseY;
// Move towards the closest axis.
var x1:Number = xPos - obstacle._x;
var x2:Number = obstacle._x + obstacle._width - xPos;
var y1:Number = yPos - obstacle._y;
var y2:Number = obstacle._y + obstacle._height - yPos;
var closestX:Number = Math.min(x1, x2);
var closestY:Number = Math.min(y1, y2);
if (closestX < closestY)
{
if (x1 < x2)
{
xPos = obstacle._x - cursor._width;
}
else
{
xPos = obstacle._x + obstacle._width;
}
}
else
{
if (y1 < y2)
{
yPos = obstacle._y - cursor._width;
}
else
{
yPos = obstacle._y + obstacle._height;
}
}
cursor._x = xPos;
cursor._y = yPos;
}
}
Anyone able to help me out here please?
Thanks in anticipation