我是游戏开发的新手,正在尝试在 flash-cs5 中创建一个简单的游戏。我在时间轴上创建了 3 个补间动画。我正在尝试停止特定的补间动画,当其他补间正在运行时单击该补间的影片剪辑,并且当再次单击停止的影片剪辑时,我想在其他补间运行时恢复补间。
提前感谢。
我是游戏开发的新手,正在尝试在 flash-cs5 中创建一个简单的游戏。我在时间轴上创建了 3 个补间动画。我正在尝试停止特定的补间动画,当其他补间正在运行时单击该补间的影片剪辑,并且当再次单击停止的影片剪辑时,我想在其他补间运行时恢复补间。
提前感谢。
以下假设您在其自己的影片剪辑中拥有每个补间动画。我不知道有什么方法可以停止一个补间而让另一个在单个电影剪辑上播放(或者如果它们都在主舞台上)。
也就是说,您可以相当轻松地停止和启动动画。下面是一个示例,说明如何在播放中停止补间动画,然后从该点恢复。
在示例中,“myMovieClip”是我们正在使用的影片剪辑。我们将不理会其余的电影剪辑,因为它们会继续自己播放。我还假设默认情况下正在播放 myMovieClip。
以下是在 AS3 中。将其放在主舞台的“动作”面板上(如果您有多个帧,则为第一帧。)
此外,请确保您已命名您的 MovieClip。为此,请在设计模式下单击舞台上的 MovieClip,然后单击属性。应该有一个文本输入框朝向该框。在那里为您的 MovieClip 写下您想要的名称。
//Declare a boolean variable that determines whether or not the movieclip timeline is playing.
var ClipPlaying:Boolean = true;
//Add the mouse click event listener to the movie clip.
myMovieClip.addEventListener(MouseEvent.CLICK, StopOrStartClip);
//Declare the function for the above event listener.
function StopOrStartClip(evt:MouseEvent):void
{
//Switch statements are my personal favorites...they're more streamlined than if statements.
switch(ClipPlaying)
{
//If the clip is playing it, we stop it and set ClipPlaying to false.
case true:
myMovieClip.stop();
ClipPlaying = false;
break;
//If the clip is not playing, we start it and set ClipPlaying to true.
case false:
myMovieClip.play();
ClipPlaying = true;
break;
}
}
这里要记住的最重要的功能是:
myMovieClip.stop();
这会将您的动画冻结在其当前位置。
myMovieClip.play();
这将从当前位置恢复动画播放。
当您使用其中任何一个时,请记住将“myMovieClip”替换为您的影片剪辑的名称!
顺便说一句,有点无关紧要,我强烈推荐这本书ActionScript 3.0 Game Programming University来学习如何创建 Flash 游戏。
您实际上不需要 5 个不同的事件侦听器、函数或变量;你可以只做一个函数来处理这一切:
stage.addEventListener(MouseEvent.CLICK, stageClick);
function stageClick(event:MouseEvent):void {
//I prefer "if" statements
if (event.target == myMovieClip1) stuff here;
else if (event.target == myMovieClip2) stuff here;
else if (event.target == myMovieClip3) stuff here;
else if (event.target == myMovieClip4) stuff here;
else if (event.target == myMovieClip5) stuff here;
}
如果需要,我可以添加更多详细信息,但这个问题是三年前的问题,所以可能不是。