AS3旋转围绕其中心点的对象 [英] AS3 Rotate an object around its center point
本文介绍了AS3旋转围绕其中心点的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
欲绕其中心而非左上角旋转此物体。 在code是这样的:
I want this object to rotate around its center rather than the top left corner. The code looks like this:
switch (event.keyCode)
{
case 37:
car.rotation = -90;
car.x -= 5;
break;
所以,当我preSS左键,车向左转,但因为它是现在它跳了一下,因为它围绕旋转的右上角。
So when i press the left key, the car turns left but as it is now it jumps up a bit because its rotating around the top corner.
感谢
推荐答案
下面将围绕中心旋转:
public function rotateAroundCenter(object:DisplayObject, angleDegrees:Number):void {
if (object.rotation == angleDegrees) {
return;
}
var matrix:Matrix = object.transform.matrix;
var rect:Rectangle = object.getBounds(object.parent);
matrix.translate(-(rect.left + (rect.width / 2)), -(rect.top + (rect.height / 2)));
matrix.rotate((angleDegrees / 180) * Math.PI);
matrix.translate(rect.left + (rect.width / 2), rect.top + (rect.height / 2));
object.transform.matrix = matrix;
object.rotation = Math.round(object.rotation);
}
有翻译对象的中心到0,0然后转动,然后将其翻译回
It translates the center of the object to 0,0 then rotate it and then translate it back.
这篇关于AS3旋转围绕其中心点的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文