我正在使用matrix.rotate方法旋轉矩形(框中的情況)。 我的旋轉事件看起來像下面如何在flex中圍繞質心旋轉矩形3
公共職能transformObject(transformEvent:TransformEvent):無效{
var numChildrn:int = _markedObjectLayer.numChildren;
var tempMatrix: Matrix = null;
var tempx:Number;
var tempy:Number;
var tempHeight:Number;
var tempWidth:Number;
for(var i:int = 0; i < numChildrn; i++){
var chld:MarkedObject = ObjectLayer.getChildAt(i)
if (chld.selected){
var height:int = (BoxObject) chld.height;
var width:int = (BoxObject) chld.width;
tempMatrix = chld.transform.matrix;
tempHeight=height;
tempWidth=width;
tempMatrix = MatrixTransformer.transform(tempMatrix,transformEvent.angle);
tempMatrix.tx=tempx;
tempMatrix.ty=tempy
chld.transform.matrix = tempMatrix;
}
}
invalidateDisplayList();
}
}
的Matrix.transform方法調用matrix.rotate方法
公共靜態函數變換(sourceMatrix:矩陣, 旋轉:編號= 0):矩陣 {
sourceMatrix = MatrixTransformer.rotate(sourceMatrix, rotation, "degrees");
return sourceMatrix;
}
/**
* Rotates a matrix and returns the result. The unit parameter lets the user specify "degrees",
* "gradients", or "radians".
*/
public static function rotate(sourceMatrix:Matrix, angle:Number, unit:String = "radians"):Matrix {
if (unit == "degrees")
{
angle = Math.PI * 2 *(angle/360);
}
sourceMatrix. rotate(angle)
return sourceMatrix;
}
問題在於x和y是盒子的核心,因此它圍繞左角旋轉。但是,如果我嘗試將temp.x和temp.y作爲質心值,它不會圍繞質心旋轉?
任何人都可以建議我在這裏做錯了什麼?
感謝 阿克沙伊
這是問題的提升http://stackoverflow.com/questions/12814859/rotating-of-box-in-flex3-using-matrix-transformation-about-center ?rq = 1 – Akshay