【问题标题】:How to check whether to add a symbol at the opening of a frame, and STOP if added?如何检查是否在帧的开头添加符号,如果添加则停止?
【发布时间】:2014-03-17 02:49:46
【问题描述】:

我的 Flash 游戏快完成了,鸭子从屏幕顶部掉下来,被困在篮子里。这段代码我基本上检查了当它们达到某个 Y 值时它们是否在篮子中,如果是,则将它们循环回屏幕顶部。如果不是,它将布尔值isOver 设置为true。我正在尝试添加gameOver 菜单,方法是在帧末尾检查isOver 是否已设置为true。我的问题是,这是一个onEnterFrame 函数,所以它不断循环愚蠢的菜单。 (添加无限的菜单实例)

这是我的代码(onEnterFrame 函数)

  function fl_EnterFrameHandler(event:Event):void
{
    if (isOver)
    {

        var overScreen = new over_screen();//adds the game over screen
        overScreen.x = 240;
        overScreen.y = 355;

        var againButton = new again_button();//adds the play again button
        againButton.x = 125;
        againButton.y = 415;

        var rateButton = new again_button();// adds the rate button
        rateButton.x = 360;
        rateButton.y = 415;

        addChild(overScreen);
        addChild(againButton);//adds the objects created above
        addChild(rateButton);
        stop(); //SHOULD stop the frame... I think? This is my problem
    }

    if (! isPaused && ! isOver) // the running code of the game, as long as it isnt paused or over
    {

        duck1.y +=  5;
        duck2.y +=  5;
        duck3.y +=  5;
        duck4.y +=  5;
        duck5.y +=  5;
        duck6.y +=  5;

        if (duck1.y > 620)
        {
            if (duck1.x < basket1.x + 50 && duck1.x > basket1.x - 50)
            {
                duck1.y = -50;
                duck1.x = Math.random() * stage.stageWidth;
                numScore++;
                score.text = numScore.toString();
            }
            else
            {
                isOver = true;
            }

        }
        if (duck2.y > 620)
        {
            if (duck2.x < basket1.x + 50 && duck2.x > basket1.x - 50)
            {
                duck2.y = -50;
                duck2.x = Math.random() * stage.stageWidth;
                numScore++;
                score.text = numScore.toString();
            }
            else
            {
                isOver = true;
            }

        }
        if (duck3.y > 620)
        {
            if (duck3.x < basket1.x + 50 && duck3.x > basket1.x - 50)
            {
                duck3.y = -50;
                duck3.x = Math.random() * stage.stageWidth;
                numScore++;
                score.text = numScore.toString();
            }
            else
            {
                isOver = true;
            }
        }
        if (duck4.y > 620)
        {
            if (duck4.x < basket1.x + 50 && duck4.x > basket1.x - 50)
            {
                duck4.y = -50;
                duck4.x = Math.random() * stage.stageWidth;
                numScore++;
                score.text = numScore.toString();
            }
            else
            {
                isOver = true;
            }
        }
        if (duck5.y > 620)
        {
            if (duck5.x < basket1.x + 50 && duck5.x > basket1.x - 50)
            {
                duck5.y = -50;
                duck5.x = Math.random() * stage.stageWidth;
                numScore++;
                score.text = numScore.toString();
            }
            else
            {
                isOver = true;
            }
        }
        if (duck6.y > 620)
        {
            if (duck6.x < basket1.x + 50 && duck6.x > basket1.x - 50)
            {
                duck6.y = -50;
                duck6.x = Math.random() * stage.stageWidth;
                numScore++;
                score.text = numScore.toString();
            }
            else
            {
                isOver = true;
            }
        }
    }

}

感谢任何帮助!

【问题讨论】:

    标签: android actionscript-3 flash


    【解决方案1】:

    解决这个问题的简单方法是让你的 Flash 游戏有 2 帧:

    在第一帧中,您在 onLoad 函数中加载菜单。 第二帧会有游戏代码,当你死后你会回到第一帧。

    【讨论】:

    • 我在想那个……我有两个场景。打开用于开始菜单,一个用于游戏。所以只是游戏场景的另一个框架?
    猜你喜欢
    • 2020-03-11
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多