Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 using a Matrix to "scale" an object from its "center"

Here's something I'm trying to figure out concerning display objects in ActionScript3 / Flex. Let's say you have a display object who's registration point is in the top left and you want to scale it from its center (middle of the display object), How could you easily acheive this with the flash.geom.Matrix class

Thanks for your help

like image 454
just_a_dude Avatar asked Nov 25 '09 16:11

just_a_dude


1 Answers

This is done by translating the object to the desired center of scale/rotation, scale/rotate it and then translate it back.

You can do that with a single matrix by concatenating the matrices to get a single matrix:

var m:Matrix = new Matrix();
m.translate(-centerX, -centerY);
m.scale(scaleX, scaleY);
m.translate(centerX, centerY);
like image 83
Aaron Avatar answered Nov 24 '22 14:11

Aaron