Пример использования rotation
Страница: 1
Сообщений 1 страница 3 из 3
Поделиться22011-09-27 10:30:50
Код:
public function Move(xdiff:Number,ydiff:Number){
var currentRotation:Number;
rot = Math.round(Math.atan(ydiff/xdiff) * (180/Math.PI));
if(xdiff < 0){
//this.rotation = 180 + rot;
rot = rot + 180
}else{
//this.rotation = rot;
}
if(rot < 0 && rot > -90){
rot = 270 + 90 + rot;
}
trace("idealrotation: " + rot + "currentrotation: " + rotation);
currentRotation = rotation;
if(currentRotation < 0){
currentRotation += 360;
}
if(rot - currentRotation > 0){
if(Math.abs(rot-currentRotation) < 5){
rotation = rot;
}else{
rotation += rotationSpeed;
}
}else if(rot - currentRotation < 0){
if(Math.abs(rot-currentRotation) < 5){
rotation = rot;
}else{
rotation -= rotationSpeed;
}
}else{
rotation = rot;
}
//this.rotation = rot;
}Поделиться32011-09-27 10:31:20
Код:
public function aim(stageX:Number, stageY:Number):void
{
var angle:Number = (Math.atan2(stageY - y, stageX - x) - Math.PI * 0.5) * 180 / Math.PI;
if (angle < 180) angle += 360;
if (angle > 180) angle -= 360;
targetAngle = angle;
}Страница: 1