Play MovieClip frame by frame in addition after same function is executed several times

若如初见. 提交于 2019-12-12 00:26:55

问题


I have a MovieClip named fails_mc, it consists of 3 soccer balls and in my game every time my player fails I need to add an X mark over 1 ball, I have a hitTestObject detecting when the ball hits the goal area, but when the ball goes outside I need to play 1 frame inside the fails_mc and add the X mark to a ball ( I have 3 different png files inside fails_mc, 1 on each frame), this is the code I’m using but I don’t know how to play frame by frame the fails_mc (keep in mind that the same function will be used every time, that’s why each frame must be added to the last played frame:

if (ball.hitTestObject(goalie))
{
    goal_mc.play();
    net_mc.play();
}
else
{
    fails_mc.play(+=1); // This is not working

    trace("It’s a fail");
}

After 3 fails I must trigger another function that will finish the game but I will figure out how to do that later on.


回答1:


I think all your looking for is the nextFrame() function of a movieClip.

you could also use gotoAndStop("x1") - where "x1" is the frame label (or number if not in quotes) you want the movieClip to goto. You could use a variable to track the current state.

var misses:int = 0;

if (ball.hitTestObject(goalie))
{

    goal_mc.play();
    net_mc.play();

}
else
{
    misses++;
    trace("It’s a fail");

    if(misses > 3){
        //do your game over stuff
    }else{
        fails_mc.gotoAndStop(misses)
    }
}


来源:https://stackoverflow.com/questions/11974731/play-movieclip-frame-by-frame-in-addition-after-same-function-is-executed-severa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!