Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 使用AS3在MovieClip中播放随机帧_Actionscript 3_Random_Frame_Movieclip - Fatal编程技术网

Actionscript 3 使用AS3在MovieClip中播放随机帧

Actionscript 3 使用AS3在MovieClip中播放随机帧,actionscript-3,random,frame,movieclip,Actionscript 3,Random,Frame,Movieclip,我有一个电影剪辑(守门员),在不同的帧中有不同的位置(内部),我想在执行一个函数后播放一个随机帧,使守门员移动到一个确定的位置,有6帧6个不同的位置,所以我需要随机播放1个位置,这是踢球后应转到随机数的代码: function moveBall() { var targetX:Number = mouseX; var targetY:Number = mouseY; var angle = Math.atan2(targetY,targetX); ball.x = mouseX +

我有一个电影剪辑(守门员),在不同的帧中有不同的位置(内部),我想在执行一个函数后播放一个随机帧,使守门员移动到一个确定的位置,有6帧6个不同的位置,所以我需要随机播放1个位置,这是踢球后应转到随机数的代码:

  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


}

非常感谢你们的帮助,很抱歉再次打扰你们,我在网上搜索了一些示例,但对于像我这样的新手来说,很多示例都非常复杂。

参考以下代码

必须从1帧随机化到最后一帧

范围的
Math.random()
大于0且小于1(浮点值)。通过使用,它实现了可用性



嗨,bitmapdata.com,很高兴再次收到你的来信,朋友!嘿,正如你看到的,我需要回到我以前的moveball函数,onenterframe的东西导致我的一个函数(if语句)被触发了很多次(我猜是一帧一帧),尽管我得到了很多帮助,我还是无法修复它。再次感谢您再次前来救援!!!很高兴能帮助你。欢迎您随时光临。:)嘿,伙计们,如果我只需要在第45,46,47,48,49,50,51,60帧之间进行选择,怎么样?问题是,我在第1帧和第44帧之间有另一个动画(守门员像在现实生活中一样移动以分散球员的注意力),感谢很多朋友
45~60
=>
int(Math.random()*16)+45
很抱歉没有得到Bitmapdata,为了正确起见,我需要选择的帧是43,44,45,46,47,48,那么它会像守门员gotoAndStop(43~48=>int(Math.random()*6)+43)吗?对不起,如果我把一切都搞砸了,朋友,我的脑子有点堵了,快凌晨3点了非常感谢您的帮助斯特里尔,将尝试这两种选择,并将保存信息,以便在未来的游戏中使用,这个地方是最佳人选,每个人都愿意提供帮助,再次感谢。
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));
    }
}
goalkeeper_mc.gotoAndStop(1 + Math.floor(Math.random() * goalkeeper_mc.totalFrames));