A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: When mouse reaches right edge come back in on the left

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    7

    When mouse reaches right edge come back in on the left

    Hi

    I have my mouse cursor set up in the scene with

    this.onMouseMove = function()
    {
    this.MyCursor._x = _xmouse;
    this.MyCursor._y = _ymouse;
    }

    where "MyCursor" is the MC for the mouse.

    Now is it possible, when I reach the outer right edge of the corresponding screen that it comes back in on the left side and visversa?

    Edit: The mouse lies on another movieclip. So it would be nice to have solution which not changes the coordinates of the underlying movie clip.

    Thanks for an answer in advance.
    Last edited by spaceharry; 07-15-2014 at 04:57 PM.

  2. #2
    Junior Member
    Join Date
    Jul 2014
    Posts
    7
    shoulnd't this here solve it when I have fullscreen? When 300 and -300 are the left and right bounds of the movie clip where the mouse lies on? But in debug mode it doesn't work.

    var Right = 300;
    var Left = -300;

    if(_xmouse> RIGHT)
    {
    _xmouse = LEFT;
    }
    else if(_xmouse < LEFT)
    {
    _xmouse = Right;
    }



    if(MyCursor._x > RIGHT)
    {
    MyCursor._x = LEFT;
    }
    else if(MyCursor._x < LEFT)
    {
    MyCursor._x = Right;
    }

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Without going over your code too much, you should not be mixing up the upper and lower case letters example(Right and RIGHT)
    It will not work as you are telling your movieclip to be at the mouse x y upon mousemove regardless of it being over or under your numbers
    Last edited by fruitbeard; 07-16-2014 at 05:19 AM.

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Perhaps this might help you along

  5. #5
    Junior Member
    Join Date
    Jul 2014
    Posts
    7
    Thanks very much, that is what I was looking for.

    Does this hitTest also works when the mouse movieclip is inside the container movieclip? I tried for a while to make this work, but didn't succeed. Or it just gave me some part of the container as the hitbox, probably related to the registration points.

    I post the code in case somebody else having the same problem.

    var right:Number = 425;/*container._x + container._width;*/
    var left:Number = 125; /*container._x;*/

    var top:Number = container._y;
    var bottom:Number = container._y + container._height;

    container.onMouseMove = function()
    {
    if (container.hitTest(_xmouse,_ymouse,true))
    {
    myCursor._x = _xmouse;
    myCursor._y = _ymouse;

    // *** x pos
    if(myCursor._x >= right - 2)
    {
    myCursor._x = left + 3;
    }
    if(myCursor._x <= left + 2)
    {
    myCursor._x = right - 3;
    }

    // *** y pos
    if(myCursor._y <= top + 2)
    {
    myCursor._y = bottom - 3;
    }
    if(myCursor._y >= bottom - 2)
    {
    myCursor._y = top + 3;
    }
    }
    };
    Last edited by spaceharry; 07-16-2014 at 02:47 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