2015-04-25 109 views
0

我正在开发一个项目,需要一个随着鼠标移动而旋转的轮子,我已经用鼠标旋转了轮子,但它围绕着角落旋转,而不是中心。围绕中心旋转物体吗?

我可以添加什么代码使其围绕中心旋转?

这是我使用至今代码:你会永远只能绕着它的起源对象

var dx : Number; 
var dy : Number; 

stage.addEventListener(Event.ENTER_FRAME, checkMouse); 

function checkMouse(evt : Event) : void 
{ 
dx = mouseX - rota.x; 
dy = mouseY - rota.y; 
rota.rotation = (Math.atan2(dy, dx) * 180/Math.PI); 
} 
+1

可能重复: //sackoverflow.com/questions/15789168/as3-rotate-an-object-around-its-center-point) – BadFeelingAboutThis

+1

编辑车轮物体,将其锚点移动到车轮的中心。应该做。 – Vesper

回答

0

,并且原点不能移动。但是,您可以将子对象移动到父对象的原点的中心。当旋转父母时,孩子似乎围绕自己的中心移动。

enter image description here

编程,如果wheelrota一个孩子,你会做以下...

wheel.x = -wheel.width/2; 
wheel.y = -wheel.height/2; 

rota.rotation = (Math.atan2(dy, dx) * 180/Math.PI) 
[AS3绕其中心点的对象(HTTP的