我在 Actionscript 中创建了一个 Sprite 并将其渲染为 Flex Canvas。认为:
var fooShape:Sprite = new FooSpriteSubclass();
fooCanvas.rawChildren.addChild(myshape);
//Sprite shape renders on screen
fooShape.rotation = fooNumber;
这将旋转我的形状,但似乎围绕左上角旋转
其父容器( Canvas )的点。
如何强制 Sprite 围绕自己的中心点旋转?我显然可以
编写代码来计算旋转,然后重新渲染,但我认为有
必须是一种内置的方式来做到这一点,当然不想“重新发明轮子”
如果可能的话。
我正在使用 FlexBuilder,因此无法访问完整的 Flash API。
非常感谢!
最佳答案
基于引用点旋转对象需要以下步骤(使用 Matrix 对象和 getBounds):
例如,将对象围绕其中心旋转 90 度:
// 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));
使用的关键方法:
关于apache-flex - Flex/ActionScript - 围绕其中心旋转 Sprite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/993445/