AS3如何实现顺时针拖动旋转
AS3如何实现用鼠标拖动一个对象进行旋转,且只能顺时针旋转。并可以实现完美到达360度,我尝试了下面这个方法,但是无法实现360度,总会差几度,不完美。希望大牛们支支招。...
AS3如何实现用鼠标拖动一个对象进行旋转,且只能顺时针旋转。并可以实现完美到达360度,
我尝试了下面这个方法,但是无法实现360度,总会差几度,不完美。
希望大牛们支支招。
var disx:Number = _mc.x - mouseX;
var disy:Number = _mc.y - mouseY;
var _rotation:Number=Math.atan2(disy,disx)/(Math.PI/180);
_mc.rotation=_mc.rotation+2;
if (_rotation>0 && _mc.rotation>=0)
{
if (_rotation>_mc.rotation)
{
_mc.rotation = _rotation;
//trace("对象=" + _mc.rotation)
}
}
else if (_rotation<0 && _mc.rotation<0)
{
if (_rotation>_mc.rotation)
{
_mc.rotation = _rotation;
}
}else if (_rotation<0 && _mc.rotation>0){
if (_rotation<_mc.rotation)
{
_mc.rotation = _rotation;
}
}else if (_rotation>0 && _mc.rotation<0){
if (_rotation>_mc.rotation)
{
_mc.rotation = _rotation;
}
}
_mc.rotation=_mc.rotation+2;
这句话是多余的,大家忽视啊! 展开
我尝试了下面这个方法,但是无法实现360度,总会差几度,不完美。
希望大牛们支支招。
var disx:Number = _mc.x - mouseX;
var disy:Number = _mc.y - mouseY;
var _rotation:Number=Math.atan2(disy,disx)/(Math.PI/180);
_mc.rotation=_mc.rotation+2;
if (_rotation>0 && _mc.rotation>=0)
{
if (_rotation>_mc.rotation)
{
_mc.rotation = _rotation;
//trace("对象=" + _mc.rotation)
}
}
else if (_rotation<0 && _mc.rotation<0)
{
if (_rotation>_mc.rotation)
{
_mc.rotation = _rotation;
}
}else if (_rotation<0 && _mc.rotation>0){
if (_rotation<_mc.rotation)
{
_mc.rotation = _rotation;
}
}else if (_rotation>0 && _mc.rotation<0){
if (_rotation>_mc.rotation)
{
_mc.rotation = _rotation;
}
}
_mc.rotation=_mc.rotation+2;
这句话是多余的,大家忽视啊! 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励10(财富值+成长值)+提问者悬赏30(财富值+成长值)
展开全部
var pressRadian:Number;
mc.addEventListener(MouseEvent.MOUSE_DOWN,mcMouseDown);
function mcMouseDown($ev:MouseEvent):void{
var dx:Number=mouseX-mc.x;
var dy:Number=mouseY-mc.y;
pressRadian=Math.atan2(dy,dx);
stage.addEventListener(MouseEvent.MOUSE_MOVE,stageMouseMove);
stage.addEventListener(MouseEvent.MOUSE_UP,stageMouseUp);
}
function stageMouseMove($ev:MouseEvent):void{
var dx:Number=mouseX-mc.x;
var dy:Number=mouseY-mc.y;
var radian:Number=Math.atan2(dy,dx);
var offset:Number=radian-pressRadian;
pressRadian=radian;
if(offset>0) mc.rotation+=offset*180/Math.PI;
}
function stageMouseUp($ev:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,stageMouseMove);
stage.removeEventListener(MouseEvent.MOUSE_UP,stageMouseUp);
}
mc.addEventListener(MouseEvent.MOUSE_DOWN,mcMouseDown);
function mcMouseDown($ev:MouseEvent):void{
var dx:Number=mouseX-mc.x;
var dy:Number=mouseY-mc.y;
pressRadian=Math.atan2(dy,dx);
stage.addEventListener(MouseEvent.MOUSE_MOVE,stageMouseMove);
stage.addEventListener(MouseEvent.MOUSE_UP,stageMouseUp);
}
function stageMouseMove($ev:MouseEvent):void{
var dx:Number=mouseX-mc.x;
var dy:Number=mouseY-mc.y;
var radian:Number=Math.atan2(dy,dx);
var offset:Number=radian-pressRadian;
pressRadian=radian;
if(offset>0) mc.rotation+=offset*180/Math.PI;
}
function stageMouseUp($ev:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,stageMouseMove);
stage.removeEventListener(MouseEvent.MOUSE_UP,stageMouseUp);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询