A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [MX04] change pt of rotation

  1. #1
    Senior Member
    Join Date
    Jun 2006

    [MX04] change pt of rotation

    hey lets say i have a square movie clip regestered at the center.



    would rotate the square about the center.

    how would I (IN ACTIONSCRIPT) change the point of regestration so i can get the square to rotate about a corner or even further.
    If anyone can help me Please feel free it IM colbyneedshelp99 (AIM).

  2. #2
    Interested User Rohm's Avatar
    Join Date
    Aug 2004
    Don't know if it's possible but otherwise you can put an pic_mc inside rotating_mc and moving the pic_mc off center which will give you the same effect.
    There is "actionally" a truth to be found in flash.

  3. #3
    Senior Member
    Join Date
    Jun 2006
    cool..... can sombody give me the mathmatics of rotation around a certain point. Im pretty sure u need arctangent.
    If anyone can help me Please feel free it IM colbyneedshelp99 (AIM).

  4. #4
    All 1s and 0s dmonkey's Avatar
    Join Date
    Nov 2005
    Leeds, UK

    It is faster and easier to do what Rohm suggests. Make your square a movieClip within another movie clip. Then by moving the movieClip of the square off-centre and rotating the parent clip, you can achieve a rotation about any point you please. However, if you really want to do it with maths:


    MovieClip.prototype.rotateAroundPoint = function(xCo:Number, yCo:Number, theta:Number) {
    //Rotate the clip by theta;
    this._rotation += theta;
    //Convert theta to radians for Maths calculations;
    theta = theta * Math.PI / 180;
    //Get the x and y disances of our clip from the rotation point;
    var xd:Number = this._x - xCo;
    var yd:Number = this._y - yCo;
    //Work out the current angle from the rotation point to our clip;
    var currentAngle:Number = Math.atan2(yd, xd);
    //Add theta to the current angle;
    var resultAngle:Number = currentAngle + theta;
    //Work out the distance from the rotation point to our clip;
    var d:Number = Math.sqrt(xd*xd + yd*yd);
    //Calculate the new x and y coordinates;
    this._x = xCo + d * Math.cos(resultAngle);
    this._y = yCo + d * Math.sin(resultAngle);

    movieClip.rotateAroundPoint(100, 100, 60);

    Simply enter the x and y coordinates of the point you want to rotate around and then the amount of rotation in degrees.
    "If I have seen further, it is by standing on the shoulders of giants." - Sir Isaac Newton

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