簡體   English   中英

如何停止as3的功能

[英]How do I stop function on 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);

該怎么辦? 或您有更好的主意。

(很抱歉有任何拼寫錯誤……我很早以前就犯了,現在我又回到了它。

我不知道它是否對您有幫助,但是無論如何。。嘗試從舞台stage.removeEventListener(Event.ENTER_FRAME, GameOver);刪除事件偵聽器stage.removeEventListener(Event.ENTER_FRAME, GameOver);

這是簡單的邏輯-您快要准備好了。

首先考慮偽代碼,不要陷入“編程”中

    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?
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM