Skip navigation
Currently Being Moderated

go to specific location

Jul 19, 2012 10:12 PM

hello,

if i have a movie clip with those X,Y cordinate (100,100) and i want him to go to (300,200) but i want to see him "walking" till he reach the location with a constant speed .

how can i do it ?

 

thank you

 
Replies
  • Currently Being Moderated
    Jul 20, 2012 4:45 AM   in reply to alaStickman

    There are a couple ways you can move an object using actionscript. 

     

    One is to use the Tween class or a third party tweening class such as Tweenlite. 

     

    Another is to use enterFrame processing to have the object's _X and _y coordinates gradually increase to the final values at constant increments (in the sample code below "yourMC would be replaced with the instance name of your movieclip).

     

    var stepsize = 2; // adjust as desired for speed

     

    this.onEnterFrame = function(){

         if(yourMC._x >= 300){

               delete this.onEnterFrame;

         } else {

               yourMC._x += 2*stepsize;

               yourMC._y += stepsize;

         }

    }

     

    As far as the walking goes, you would need to have the movieclip do the animation of the stepping.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 20, 2012 1:22 PM   in reply to alaStickman

    Yes, in this case if the value of x is equal or greater than the final value (300) then that line of code will stop the enterframe function from working.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points