本文介绍了播放随机框架内与影片剪辑AS3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个影片剪辑(门将),在不同的帧(内部),我想执行一个功能,使守门员移动到一个确定的位置之后打一个随机帧不同的位置,有6架有6个不同的位置,所以我需要随机播放1的位置,这是code应该去随机数球被踢后:

I have a movie clip (goalkeeper) with different positions in different frames (inside), I would like to play a random frame after executing a function to make the goalkeeper move to a determinate position, there are 6 frames with 6 different positions so I need to play 1 position randomly, this is the code that should go to the random number after ball is kicked:

  function moveBall()
  {
var targetX:Number = mouseX;
var targetY:Number = mouseY;
var angle = Math.atan2(targetY,targetX);
ball.x =  mouseX + Math.cos(angle);
ball.y =  mouseY + Math.sin(angle) ;
ballRotation = true;

if (ballRotation==true)
{


    goalkeeper_mc.gotoAndStop( Random Frame);//Here is when I need to go and play the random frame everytime function is executed


}

非常感谢您的帮助球员,对不起,打扰一次,我在网上搜索了一些例子,但我发现很多人真的复杂,像我这样的新手。

Thanks a lot for your help guys, sorry for bothering again, I searched the web for some examples but I found many of them really complicated for a newbie like me.

推荐答案

指一个下code。

您必须随机从1帧到最后一帧。

you must randomize from 1 frame to last Frame.

的Math.random()的范围是大于0且小于1(浮动值)。利用它实现可用。

Math.random () of the range is greater than 0 and less than 1(floating-value). by use it implements available.

function moveBall()
{
    var targetX:Number = mouseX;
    var targetY:Number = mouseY;
    var angle = Math.atan2(targetY,targetX);
    ball.x =  mouseX + Math.cos(angle);
    ball.y =  mouseY + Math.sin(angle) ;
    ballRotation = true;

    if (ballRotation==true)
    {
        goalkeeper_mc.gotoAndStop(int(Math.random * (goalkeeper_mc.totalFrames)+1));
    }
}

这篇关于播放随机框架内与影片剪辑AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:18