2015-12-25 47 views
0

呃...我试着停止在as3上编码的动画,但不能这样做。这里的代码!如何在as3上停止功能

//this make the ground move 
function GroundAndEndingMove(event:Event):void 
{ 
    ground.x = ground.x - 5; 
    if (ground.x <= -846.24) 
    { 
     ground.x = -846.25; 
     ending.x = 503.5; 
     stop(); 

    } 
    stopmation.x = stopmation.x - 5; 
    if (stopmation.x <= -846.24)  
    { 
     ground.x = -846.25; 
     ending.x = 503.5; 
     stop(); 
    } 
    ending.x = ending.x - 5.1; 
    if (ending.x <= 503.5) 

    { 
     rowl.x = 548.1; 
     ending.x = 503.5; 
     stop(); 
    } 
    trash.x = trash.x - 5.1; 
    if (trash.x <= 503.5) 
    { 
     trash.x = 503.5; 
     ball.x = ball.x + 5.1; 
     stop(); 
    } 

} 
stage.addEventListener(Event.ENTER_FRAME, GroundAndEndingMove); 

//this function make the ball to faled 

function GameOver(event:Event):void 
{ 
    if(ball.hitTestObject(ground)) 
    { 
     //here I should stop the animation wherever it be. 
    } 
    if (ball.hitTestObject(stopmation)) 
    { 
     //also here 
    } 

} 
stage.addEventListener(Event.ENTER_FRAME, GameOver); 

怎么办?或者你有什么更好的想法.. 帮助!

(对不起任何拼写错误......我做了很久以前,我回到它现在..)

回答

0

我不知道它是否帮助你,但无论如何..尝试删除事件来自舞台的听众stage.removeEventListener(Event.ENTER_FRAME, GameOver);

0

这很简单 - 你几乎就在那里。

想想伪代码第一,不以 “编程”

if (A is true OR B is true) then 
    // end game: do cleanup etc. 
    // off user some option (new game, etc) 
    end if 

function GameOver(event:Event):void 
{ 
    if(ball.hitTestObject(ground) || ball.hitTestObject(stopmation)) 
    { 
    stage.removeEventListener(Event.ENTER_FRAME, GroundAndEndingMove); 
    stage.removeEventListener(Event.ENTER_FRAME, GameOver); 

    // all cleaned up: what happens now? 
    } 
} 
被抓到