我不确定你试图做出什么行为,但我认为问题在于
centerX
和
centerY
定义的中间
_background
在里面
_background.parent
的
坐标空间。然后你正在翻译
matrix
因此
_背景
围绕值旋转
centerX, centerY
,但在
_背景
的坐标空间。
假设你想要
_背景
要围绕屏幕上保持静止的点旋转,实际需要做的是使用两个不同的
Points
:
matrix.translate(-_rotateAroundPoint.x, -_rotateAroundPoint.y);
matrix.rotate(currentRotation / 180) * Math.PI);
matrix.scale(currentScaleX, currentScaleY);
matrix.translate(_centerOnPoint.x, _centerOnPoint.y);
哪里
_rotateAroundPoint
是围绕哪个点
_背景
应该上交
自身坐标空间
和
_centerOnPoint
是它应该转向的点
父母的
坐标空间。
这两个值只需要在要平移时重新计算
_背景
,而不是每一帧。例如:
private var _rotateAroundPoint:Point = new Point(_background.width * 0.5, _background.height * 0.5);
private var _centerOnPoint:Point = new Point(50, 50);
private function renderPage(e:Event) {
var matrix:Matrix = new Matrix();
matrix.translate(-_rotateAroundPoint.x, -_rotateAroundPoint.y);
matrix.rotate((currentRotation / 180) * Math.PI);
matrix.scale(currentScaleX, currentScaleY);
matrix.translate(_centerOnPoint.x, _centerOnPoint.y);
_background.transform.matrix = matrix;
}