A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] How to gradually move to mouse location?

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

    resolved [RESOLVED] How to gradually move to mouse location?

    Well, I got some code here that will move the player to the mouses x/y location, but I want to gradually move them to this location so it doesnt look like their teleporting

    Code:
    //check left mouse button is down
    if(Key.IsDown(1)){
    //move player to mouse location
    _root.player._x = _root._xmouse;
    _root.player._y = _root._ymouse;
    }

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

    You could use a simple built in tween like so (or similar)
    PHP Code:
    import mx.transitions.*;

    var 
    target:MovieClip _root.player;

    onMouseDown = function ()
    {
        
    //if (Key.isDown(1))
        //{
            //trace("left mouse click");
            
    var tweenX = new Tween(target"_x"None.easeNonetarget._x_root._xmouse0.5true);
            var 
    tweenY = new Tween(target"_y"None.easeNonetarget._y_root._ymouse0.5true);
        
    //}
    }; 
    I'm not sure if the key(1) is necessary as you only have one key really, the right click brings up the menu, and it won't work with a mac as it has virtually no left click, so maybe leave the commented parts commented or remove them

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks, that works pretty well to what I wanted
    and I'll just remove the comments, thanks again

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