A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: custom cursor easing around object

  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    293

    custom cursor easing around object

    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 0obstacleList.lengthi++)
            {
                
    // 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(mouseXmouseY))
                {
                    
    moveCursorOutsideObstacle(obstacleList[i], mouseXmouseY);
                    break;
                }
            }
        }
        
        public function 
    moveCursorOutsideObstacle(obstacle:MovieClipmouseX:NumbermouseY: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(x1x2);
            var 
    closestY:Number Math.min(y1y2);
            
            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
    Last edited by WWFC; 04-07-2008 at 12:21 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center