Hi All,
I am hoping that someone can put me out of my misery here.
I have an fla file that contains three mc’s - one mc is titled ‘cursor’ and as the name implies it follows the users cursor around the stage. The other two mc’s are irregular shaped mc’s named obstacle1 and obstacle2 - these two mc’s stop the cursor mc moving through them and the cursor mc stops at the border of the mc shape.
What I need to do and hope someone can help me out here - is to make the cursor mc slide/ease around the irregular shape of the obstacle mc’s. Is this possible?
I have seen similar things - but can’t find any reference to it now!
Currently the cursor mc works great when the shape is square/rectangle - but when the shape is irregular it still stops at the border of the whole shape area and not the ‘actual’ shape.
How do I tell it to follow the irregular shape?
The other thing (if possible) I would like it to do is slide around the borders of the irregular shape depending on where the users mouse is within the obstacle mc - for example if the users mouse is at the top of the obstacle mc, the cursor mc is also at the top border - but if I move the mouse to the bottom of the mc - the cursor mc jumps to the bottom border of the obstacle - is there any way of making the cursor mc slide/ease around the obstacles borders rather than suddenly jump?
The fla that I have attached contains a .as file that controls the movement and constraints and looks like this:
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*.hitTest(mouseX, mouseY))
{
moveCursorOutsideObstacle(obstacleList*, 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;
}
}
I have tried to get this working but I think it is just over my head!!!
Anyone know how to do the above???
…please?..