This is a blog about Flash & AS by betaruce :-)



Calendar

June 2007
M T W T F S S
« May    
  1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

September 18, 2005

Flash 8 Tips: Matrix

Filed under: Using Flash — betaruce @ 2:45 am

We can use Matrix to do scaling and rotation on MovieClips. However, if we use the method scale() and rotate() of the Matrix class, the translation of the mc will also be affected, i.e. the tx and ty values are also changed.

Therefore, I may not use scale() if I want to scale a mc with matrix. Instead I will do the following (assume that there’s a movieclip named “mc” on the stage):

mat = mc.transform.matrix;
mat.a += .1;
mat.d += .1;
mc.transform.matrix = mat;

Scaling is done simply by changing the values of a and d.

For rotation, however, since I do not want to do so many sin and cos calculations, I still apply the rotate() method, and afterwards change the tx and ty back to their original values.

mat = mc.transform.matrix;
mat2 = mat.clone();
mat.rotate(Math.PI/6);
mat.tx = mat2.tx;
mat.ty = mat2.ty;
mc.transform.matrix = mat;

By using either of these 2 methods, we can do scaling and rotation with the mc remain in the same place (but not moving away).

• • •

2 Comments »

  1. Interesting read but do you happend to know why when you apply a transform in the matrix to a tween it stops working?

    Comment by Svetoslav — September 29, 2005 @ 3:34 pm
  2. do you mean that you apply it to a MC that is undergoing Motion tween?

    Comment by betaruce — September 29, 2005 @ 9:11 pm

Comments RSS • TrackBack URI

Leave a comment

Powered by: WordPress • Template by: Priss