当我的时间计数器显示 0 (Flash Builder) 时,如何在主类中添加我的 GameOver-Page?

发布于 2024-12-11 21:20:18 字数 601 浏览 2 评论 0原文

    public function SeedsAndPots()

    {
        startpage = new StartPage();
        addChild(startpage);

        buttonPage = new ButtonPage();
        addChild(buttonPage);
        buttonPage.addEventListener(MouseEvent.CLICK, GoToGame);    

    }
    public function GoToGame(e:MouseEvent):void
    {
        removeChild(startpage);
        buttonPage.removeEventListener(MouseEvent.CLICK, GoToGame);
        removeChild(buttonPage);
        gamePage = new GamePage();
        addChild(gamePage);

    }

// 我想做一个函数,如果时间为 0,我应该转到我的 GameOver-Page。
}
}

    public function SeedsAndPots()

    {
        startpage = new StartPage();
        addChild(startpage);

        buttonPage = new ButtonPage();
        addChild(buttonPage);
        buttonPage.addEventListener(MouseEvent.CLICK, GoToGame);    

    }
    public function GoToGame(e:MouseEvent):void
    {
        removeChild(startpage);
        buttonPage.removeEventListener(MouseEvent.CLICK, GoToGame);
        removeChild(buttonPage);
        gamePage = new GamePage();
        addChild(gamePage);

    }

// I wanna do a function that says that if time is 0 i should go to my GameOver-Page.
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷荒 2024-12-18 21:20:18

创建一个倒计时变量来反映时间(以秒为单位)。

当您加载游戏页面时实例化一个计时器以每秒倒计时。

当时间达到 0 时,应用逻辑结束当前关卡并显示游戏结束页面。

    // store time remaining in a countdown timer
    protected var countdown:uint = 60;

    // create a timer, counting down every second
    protected var timer:Timer;

    // in your go to game, or when you want to start the timer      
    public function GoToGame(e:MouseEvent):void
    {
        // ... your go to game function

        // start your countdown timer.
        timer = new Timer(1000);
        timer.addEventListener(TimerEvent.TIMER, timerHandler);
        timer.start();
    }

    protected function timerHandler(event:TimerEvent):void
    {
        // countdown a second
        --countdown;

        // update any counter time text field display here...

        // if you've reached 0 seconds left
        if(countdown == 0)
        {
            // stop the timer
            timer.removeEventListener(TimerEvent.TIMER, timerHandler);
            timer.reset();

            // remove current gamePage
            // addChild to your game over page.
        }
    }

Create a countdown variable to reflect time in seconds.

Instantiate a timer when you load your game page to countdown every second.

When time has reached 0, apply the logic to end the current level and display your game over page.

    // store time remaining in a countdown timer
    protected var countdown:uint = 60;

    // create a timer, counting down every second
    protected var timer:Timer;

    // in your go to game, or when you want to start the timer      
    public function GoToGame(e:MouseEvent):void
    {
        // ... your go to game function

        // start your countdown timer.
        timer = new Timer(1000);
        timer.addEventListener(TimerEvent.TIMER, timerHandler);
        timer.start();
    }

    protected function timerHandler(event:TimerEvent):void
    {
        // countdown a second
        --countdown;

        // update any counter time text field display here...

        // if you've reached 0 seconds left
        if(countdown == 0)
        {
            // stop the timer
            timer.removeEventListener(TimerEvent.TIMER, timerHandler);
            timer.reset();

            // remove current gamePage
            // addChild to your game over page.
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文