Actionscript 3 actionscript 2到actionscript 3我的代码
有人能帮我把这段代码从as2转换成as3吗 对于一个简单的圆,我想当我向右移动鼠标光标时,这个圆要旋转(不需要移动鼠标光标,但这个圆仍在旋转) 我知道Actionscript 3 actionscript 2到actionscript 3我的代码,actionscript-3,actionscript,actionscript-2,Actionscript 3,Actionscript,Actionscript 2,有人能帮我把这段代码从as2转换成as3吗 对于一个简单的圆,我想当我向右移动鼠标光标时,这个圆要旋转(不需要移动鼠标光标,但这个圆仍在旋转) 我知道\u root.\u xmouse转到mouseX和this.\u rotation转到this.DisplayObject.rotation onClipEvent(enterFrame) { this.xmouse = Math.min(908, Math.max(0, _root._xmouse)); if (_root._x
\u root.\u xmouse
转到mouseX和this.\u rotation
转到this.DisplayObject.rotation
onClipEvent(enterFrame)
{
this.xmouse = Math.min(908, Math.max(0, _root._xmouse));
if (_root._xmouse > 0)
{
var offset = Stage.width / 2 - this.xmouse;
this._rotation = this._rotation + offset / 2000;
} else {
this._rotation = this._rotation - 0.02;
}
this._rotation = this._rotation % 180;
}
AS3版本:
stage.addEventListener( Event.ENTER_FRAME, mouseOver );
function mouseOver( e: Event ) : void
{
rota.mouseX == Math.min(908, Math.max(0, stage.mouseX));
if (stage.mouseX > 0)
{
var offset = stage.stage.width / 2 - rota.mouseX;
rota.rotation = rota.rotation + offset / 2000;
}else{
rota.rotation = rota.rotation - 0.02;
}
rota.rotation = rota.rotation % 180;
}
这应该起作用:
var offset : int = 0; //declare the variable (integer)
//stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoving );
rota.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoving );
function mouseMoving ( evt : Event ) : void
{
rota.x = stage.mouseX; //Math.min(908, Math.max(0, stage.mouseX));
if (stage.mouseX > 0)
{
offset = stage.stage.width / 2 - rota.mouseX;
rota.rotation = rota.rotation + offset / 2000;
}else{
rota.rotation = rota.rotation - 0.02;
}
rota.rotation = rota.rotation % 180;
}
注意事项/提示:
- 尽可能在函数之外声明变量
中的(evt:Event)
是您对任何附加了evt
的对象的目标引用。因此,如果你想移动不止一个东西,只需给它们所有相同的.addEventListener(MouseEvent.MOUSE\u MOVE)
像addEvent
一样,但是你可以看到函数目前只移动rota.addEvent…
,所以通过将代码更改为使用rota
和evt.rotation
等。。。evt的evt.mouseX
功能现在使任何收听该evt
功能的人都可以使用通用功能mouseMoving
编辑(基于评论): 变量
speed
设置旋转速度。对于旋转
通过-=
或+=
设置方向
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoving ); //Stage : for direction
rota.addEventListener(Event.ENTER_FRAME, mouseRotating); //Object : for spin/rotate
var prevX:int = 0;
var currX:int = 0;
var directX: int = 0; //will update to 1=Left or 2=Right
var speed : int = 7; //speed of rotation
function mouseMoving ( evt : Event ) : void
{
prevX = currX; currX = stage.mouseX;
if (prevX > currX) { directX = 1; } //moving = LEFT
else if (prevX < currX) { directX = 2; } //moving = RIGHT
//else { directX = 0;} //moving = NONE
}
function mouseRotating ( evt : Event ) : void
{
evt.target.x = stage.mouseX; //follow mouse
if ( directX == 1 ) { evt.currentTarget.rotation -= speed; }
if ( directX == 2 ) { evt.currentTarget.rotation += speed; }
}
stage.addEventListener(MouseEvent.MOUSE\u MOVE,mouseMoving)//阶段:为指导
rota.addEventListener(Event.ENTER_FRAME,鼠标移动)//对象:用于旋转/旋转
var-prevX:int=0;
var currX:int=0;
var directX:int=0//将更新为1=左或2=右
无功转速:int=7//转速
函数mouseMoving(evt:事件):void
{
prevX=currX;currX=stage.mouseX;
如果(prevX>currX){directX=1;}//moving=LEFT
else如果(prevX
“不需要移动鼠标光标,但圆圈仍在旋转”。。。这就是EnterFrame
所做的。它以SWF的FPS速率重复代码。也许你想在鼠标移动
侦听器中使用该代码逻辑?显示您试图制作的AS3版本代码,以便帮助您修复。是的,可能是鼠标移动侦听器,此as2代码可能如何工作(作为AS3代码)…我们需要查看您到目前为止的AS3代码,以显示如何应用as2逻辑。例如:没有人知道你的圆变量名等。。您可以用圆圈变量名替换此
,并将其用作circleName.rotation=circleName.rotation%180
etc等“为我转换此代码”和“编写我的代码”问题不适用于Stackoverflow。看见我愿意帮助您纠正AS3工作中的任何错误。使用按钮添加您的AS3努力,以获得更快的答案。总之\u root.
是一个3阶段。
等等。而且这个
也不是必需的,所以只需使用测试
或事件。currentTarget
(currentTarget与鼠标移动侦听器对话)。如果没有AS3代码查看,很难给您提供建议。好的,我添加了AS3版本。我喜欢这个,谢谢,如果我想让圆圈继续向右移动,如果我向右移动鼠标,然后我停止移动鼠标,但圆圈仍向右旋转(向左旋转相同),我该怎么办?谢谢,但你现在能不接受答案吗?。我正试图让我的代表得分达到6-6-6-6
,因为我和朋友开了一个玩笑,✓代码>已将其推得太远。你总是可以在周末后这样。我需要先上Flash。可能在1小时内。另外,我认为您需要一个不同于其他AS2和AS3代码的逻辑。您不需要角度。旋转%180代码>等等…嗯。。我会等的!:)Thanks@romania检查新编辑是否符合您的要求?注:“1小时内”应为“1天内”。让我知道进展如何。