# How to use rotateAroundCenter with a Matrix object

**URL:** https://forum.kirupa.com/t/how-to-use-rotatearoundcenter-with-a-matrix-object/265912
**Category:** flash
**Created:** [July 14, 2008, 2:58pm UTC](https://forum.kirupa.com/t/how-to-use-rotatearoundcenter-with-a-matrix-object/265912 "2008-07-14T14:58:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kitsunegari](https://avatars.discourse-cdn.com/v4/letter/k/eb8c5e/32.png) [@kitsunegari](https://forum.kirupa.com/u/kitsunegari)
#### Post date: [July 14, 2008, 2:58pm UTC](https://forum.kirupa.com/t/how-to-use-rotatearoundcenter-with-a-matrix-object/265912/1 "2008-07-14T14:58:36Z")

</div>

I have a question concerning the use of the matrix object  
The following code works well to rotate the sprite from its center if its x and y properties don’t change.  
However, if I drag and drop the clip somewhere else after having rotated it, and then add a new rotation, it keeps rotating from the previous rotation point. Even if I add **point =new Point(myspr.x+myspr.width/2, myspr.y+myspr.height/2);** in a function that is called at the end of the drag and drop, the rotation point remains the same.  
So, do you have any idea how to update the position of the matrix rotation point if the x and the y of the clip change on the scene after a rotation? (I hope my question is clear enough)  
Thanks

```auto
var myspr=new Sprite();
myspr.x=100;
myspr.y=100;
addChild (myspr);
var point:Point=new Point(myspr.x+myspr.width/2, myspr.y+myspr.height/2);
rotateAroundCenter(myspr,45);
function rotateAroundCenter (ob:*, angleDegrees) {
    var m:Matrix=ob.transform.matrix;
    m.tx -= point.x;
    m.ty -= point.y;
    m.rotate (angleDegrees*(Math.PI/180));
    m.tx += point.x;
    m.ty += point.y;
    ob.transform.matrix=m;
} 

```

---

<div class="post-metadata">

### Author: ![yaim0310](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@yaim0310](https://forum.kirupa.com/u/yaim0310)
#### Post date: [July 14, 2008, 7:58pm UTC](https://forum.kirupa.com/t/how-to-use-rotatearoundcenter-with-a-matrix-object/265912/2 "2008-07-14T19:58:29Z")

</div>

you would just put the new point inside the function.

```auto
function rotateAroundCenter (ob:*, angleDegrees) {
    var point:Point = new Point(ob.x + ob.width/2,ob.y + ob.height/2);
    var m:Matrix=ob.transform.matrix;
    m.tx -= point.x;
    m.ty -= point.y;
    m.rotate (angleDegrees*(Math.PI/180));
    m.tx += point.x;
    m.ty += point.y;
    ob.transform.matrix=m;
}

```

but this will not work more then once. did you test if you rotate an object more then once? (myspr.x+myspr.width/2, myspr.y+myspr.height/2) is the center of a non-rotated object, but once you rotate it, thats no longer the center of the object. so it will begin to rotate out of control and off the screen if you keep rotating it that way.

if you want to do it similar to that way:

```auto
import fl.motion.MatrixTransformer;

var myspr=new Sprite();
myspr.x=100;
myspr.y=100;
myspr.centerW = myspr.width/2;
myspr.centerH = myspr.height/2;
addChild (myspr);

rotateAroundCenter(myspr,45);

function rotateAroundCenter (ob:*, angleDegrees) {
	var mat:Matrix = ob.transform.matrix
	MatrixTransformer.rotateAroundInternalPoint(mat,ob.centerW,ob.centerH,angleDegrees);
	ob.transform.matrix = mat;
}

```

you’d just need to make custom variables of the objects width and height before you rotate it so those aren’t effected by the rotation

---

<div class="post-metadata">

### Author: ![skineh](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@skineh](https://forum.kirupa.com/u/skineh)
#### Post date: [July 15, 2008, 3:19pm UTC](https://forum.kirupa.com/t/how-to-use-rotatearoundcenter-with-a-matrix-object/265912/3 "2008-07-15T15:19:22Z")

</div>

hehe, I’d already plugged your TransformMatrixProxy on his duplicate post at the gtal forums. 🙂 Looked helpful to me!

---

<div class="post-metadata">

### Author: ![Gathan](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@Gathan](https://forum.kirupa.com/u/Gathan)
#### Post date: [July 15, 2008, 5:03pm UTC](https://forum.kirupa.com/t/how-to-use-rotatearoundcenter-with-a-matrix-object/265912/4 "2008-07-15T17:03:01Z")

</div>

In answer to your question, heres a very simple example of a matrix transformation on a movieclip around its center.

---

<div class="post-metadata">

### Author: ![yaim0310](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@yaim0310](https://forum.kirupa.com/u/yaim0310)
#### Post date: [July 15, 2008, 5:39pm UTC](https://forum.kirupa.com/t/how-to-use-rotatearoundcenter-with-a-matrix-object/265912/5 "2008-07-15T17:39:46Z")

</div>

Gathan - I think the point is to be able to rotate around the center without offsetting the x and y with negitives on the movieclip like you did.
