对你们来说很容易,但对我来说很新。我有一个名为mcPlayer的动画行走角色。在它的时间轴内,我在各种动画状态“walkingLeft”,“walkingRight”和“Idle”中都有帧标签。步行动画是他走在一个地方。我希望能够使用按钮将带有动作的角色移动到舞台上的各种目标,并在移动时播放相应的动画。所以我能想到的最直接的方式就是这样......
import com.greensock.*;
btnRight.addEventListener(MouseEvent.CLICK, moveRight);
btnLeft.addEventListener(MouseEvent.CLICK, moveLeft);
function moveRight(Evt:MouseEvent):void{
TweenLite.to(mcPlayer,2,{x:450});
mcPlayer.gotoAndPlay("walkingRight");
}
function moveLeft(Evt:MouseEvent):void{
TweenLite.to(mcPlayer,2,{x:450});
mcPlayer.gotoAndPlay("walkingLeft");
}
我在mcPlayer时间轴上尝试了不同的命令,比如,设置一个stop();在每个动画的开头。我试过把gotoandplay();在每个动画结束时所以它将转到开头并循环。我想尽可能少地使用时间轴。
我如何...... 1.在补间运动时让动画连续播放 2.动画到达目的地后停止 在mcPLayer达到目标后,最终让动画“闲置”。
答案 0 :(得分:1)
要循环动画,您将测试动画的最后一帧,然后循环返回,您可以使用onUpdate参数在补间中执行此操作,并使用onUpdateParams传递更新所需的任何数据。例如动画标签和动画的最后一帧。
如果要在补间完成后执行某些操作(例如更改为空闲动画),则需要使用onComplete参数。
以下是您可能会做的一个示例:
btnRight.addEventListener(MouseEvent.CLICK, moveRight);
btnLeft.addEventListener(MouseEvent.CLICK, moveLeft);
function moveRight(Evt:MouseEvent):void{
// lastframe should be replaced with whatever the frame the walk right animation ends on.
TweenLite.to(mcPlayer, 2, {x:450, onUpdate:updateHandler, onUpdateParams:['walkingRight', lastFrame], onComplete:idleHandler);
mcPlayer.gotoAndPlay("walkingRight");
}
function moveLeft(Evt:MouseEvent):void{
// lastframe should be replaced with whatever the frame the walk left animation ends on.
TweenLite.to(mcPlayer, 2, {x:10, onUpdate:updateHandler, onUpdateParams:['walkingLeft', lastFrame], onComplete:idleHandler);
mcPlayer.gotoAndPlay("walkingLeft");
}
function updateHandler(loopLabel:String, lastFrame:int):void
{
if (mcPlayer.currentFrame == lastFrame)
{
mcPlayer.gotoAndPlay(loopLabel);
}
}
function idleHandler():void
{
mcPlayer.gotoAndPlay("idle");
// this is also where you'd do anything else you need to do when it stops.
}
我不确定你的内容是如何设置的,我只是猜测你在mcPlayer的时间轴上拥有所有动画,并根据你所说的内容为每个动画制作标签。
根据您的内容设置方式,您可能需要以不同方式实施。但概念仍然相同 - 使用onComplete和onUpdate处理这些特定事件的事情。