我如何移动一个物体,并能够在它移动时实际地看到它?不只是消失和出现在不同的位置,就像使用下面的代码一样。
buttonL2_btn.addEventListener(MouseEvent.CLICK,左); 函数左(事件:事件):void{ box_mc.x =241.5;}
这将将myObject移动到指定的任何位置,但我再次希望能够在移动时看到它。
发布于 2013-01-10 15:54:17
在您的示例中,您只是在按下某个按钮时设置它的X位置,当您需要将X更改为EnterFrame事件时,如下所示:
this.addEventListener(Event.ENTER_FRAME, move);
function move(event:Event):void{
box_mc.x -= 5
}您的box_mc应相应地向左移动5个像素与框架。
你可以很容易地使用一个宽松的库。我强烈推荐TweenMax。
发布于 2013-01-11 14:24:05
好吧,我有点厌倦了人们不断地建议一些推特引擎。当然,他们很摇滚,但这无助于了解他在做什么。
为了用一个非常容易移动的对象移动一个对象,我建议在一个onEnterFrame事件中为对象移动以下代码:
addEventListener(Event.ENTER_FRAME, onEnterFrame);
var xGoal:Number = 100; //:: The target X destination for your object
var yGoal:Number = 100; //:: The target Y destination for your object
var smothness:Number = 10; //:: Smoothness factor for movement. The lower the value the faster the movement.
function onEnterFrame(e:Event):void
{
box_mc.x += (xGoal - box_mc.x) / smothness;
box_mc.y += (yGoal - box_mc.y) / smothness;
}将移动/轻松您的盒子对象到想要的位置与设置平滑。
发布于 2013-01-10 17:45:08
您可以安装437个可用的推特引擎中的任何一个。
或者您可以添加几行代码。
设置一个保存目标值的变量。
var dest:Number = 241.5; // this is what gets updated on mouse click关于盒子的肠框架事件:
function onBoxEnterFrame(e:MouseEvent):void{
if (dest != box_mc.x){
var easeNum:Number = 0.4 // between 0 and 1, the higher the number, the slower the transition
box_mc.x = box_mc.x * easeNum + dest * (1-easeNum);
}
}您可以在位置接近(小于0.1差)时再增加几行,或者使用一个更线性的变化,像box_mc.x += 5;一样增量地调整,直到它与最大的数字匹配为止。
https://stackoverflow.com/questions/14261783
复制相似问题