A Flash Developer Resource Site

# Thread: [MX04] change pt of rotation

1. ## [MX04] change pt of rotation

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

so

_rotation+=5

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.  Reply With Quote

2. 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.  Reply With Quote

3. cool..... can sombody give me the mathmatics of rotation around a certain point. Im pretty sure u need arctangent.  Reply With Quote

4. Hi,

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:

code:
```
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);
}

//Example
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.  Reply With Quote

#### Posting Permissions

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

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap 