AS3 how to go to next frame in MainTimeline when character die animation ends

倾然丶 夕夏残阳落幕 提交于 2019-12-20 07:09:16

问题


so I need to know if my character(bird) hitTestObject with pipe he plays the die animation after the animation ends it need to go to the game over frame in the main timeline

if (bird.hitTestObject(pipe1)) {

 bird.gotoAndStop(3); //frame 3 = where the die animation is 

}

LINK 1 (here you see different frames for animations frame 3 is die animation) http://gyazo.com/67381832827bfb8a4dac2452076a4217

LINK 2 (the die animation) http://gyazo.com/bf5153a9d00e1478471fff7b73d0c592

so here you can see the animation in the end of the animation there need code to go to game over frame in the main timeline frame 3

btw its not in a .as file but in the timeline

thank you if you can help me and if my english is not good sorry about that im dutch


回答1:


Try using an enter frame event, like so:

if (bird.hitTestObject(pipe1)) {

    bird.gotoAndStop(3); //frame 3 = where the die animation is 
    addEventListener(Event.ENTER_FRAME, waitForDeathAnimationToEnd);

}

function waitForDeathAnimationToEnd(e:Event)
{
    if(bird.currentFrame === bird.totalFrames)
    {
        removeEventListener(Event.ENTER_FRAME, waitForDeathAnimationToEnd);
        bird.stop();
        gotoAndStop(frameOrFrameLabelWhereYourGameOverFrameIs); //Replace with Game Over frame label or number
    }
}


来源:https://stackoverflow.com/questions/21832544/as3-how-to-go-to-next-frame-in-maintimeline-when-character-die-animation-ends

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