更新时间:2023-02-02 17:46:18
根据参考点旋转对象需要以下步骤(使用 Matrix 对象和 getBounds):
The following steps are required to rotate objects based on a reference point (using Matrix object and getBounds):
例如,将对象围绕其中心旋转 90 度:
For example to rotate an object 90 degrees around its center:
// Get the matrix of the object
var matrix:Matrix = myObject.transform.matrix;
// Get the rect of the object (to know the dimension)
var rect:Rectangle = myObject.getBounds(parentOfMyObject);
// Translating the desired reference point (in this case, center)
matrix.translate(- (rect.left + (rect.width/2)), - (rect.top + (rect.height/2)));
// Rotation (note: the parameter is in radian)
matrix.rotate((90/180)*Math.PI);
// Translating the object back to the original position.
matrix.translate(rect.left + (rect.width/2), rect.top + (rect.height/2));
使用的关键方法:
Key methods used: