0

我的游戏有问题。
当我玩 1 级并返回主菜单时,新游戏按钮不再起作用。
有谁知道可能是什么问题?

这就是我在主菜单中的内容:

package  
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import HomeTitel;
import InstBtn;
import NieuwBtn;    

public class Hoofdmenu extends MovieClip 
{
    private var homeTitel:HomeTitel;
    private var instBtn:InstBtn;
    private var nieuwBtn:NieuwBtn;
    private var inst:Instructions;
    private var level1:Level1;

    public function Hoofdmenu():void 
    {
        placeHomeTitel();
        placeInstructionsBtn();
        placeNieuwBtn();
    }

    private function placeHomeTitel():void
    {
        homeTitel = new HomeTitel();
        addChild(homeTitel);
        homeTitel.x = 275;
        homeTitel.y = 20;
    }

    private function placeInstBtn():void
    {
        instBtn = new InstBtn();
        addChild(instBtn);
        instBtn.x = 275;
        instBtn.y = 225;
        instBtn.addEventListener(MouseEvent.CLICK, gotoInstructions);
    }

    private function gotoInstructions(event:MouseEvent)
    {
        inst = new Instructoins();
        addChild(inst);
    }

    private function placeNewBtn():void
    {
        newBtn = new NewBtn();
        addChild(newBtn);
        newBtn.x = 275;
        newBtn.y = 175;
        newBtn.addEventListener(MouseEvent.CLICK, gotoLevel1);
    }

    private function gotoLevel1(event:MouseEvent):void
    {
        level1 = new Level1();
        addChild(level1);
    }

}

}

这就是我在 level1 中的内容:

package 
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import L1Achtergrond;
import L1Titel;
import MenuBtn;
import Sun;
import Min;
import GameOver;
import WellDone;
import VolgLevel;
import HoofdmenuBtn;
import Opnieuw;

public class Level1 extends MovieClip
{
    private var back:L1Achtergrond;
    private var titel:L1Titel;
    private var menu:MenuBtn;
    private var sun:Sun;
    private var aantalSun:int = 5;
    private var counter:int;
    private var sunArray:Array = new Array();
    private var timer:Timer;
    private var min:Min;
    private var gameover:GameOver;
    private var welldone:WellDone;
    private var volglevel:VolgLevel;
    private var opn:Opnieuw;
    private var hoofdBtn:HoofdmenuBtn;
    private var level1:Level1;
    private var level2:Level2;
    private var hoofdmenu:Hoofdmenu;

    public function Level1():void
    {
        back = new L1Achtergrond();
        addChild(back);

        placeTitel();

        timer = new Timer(3000,1);
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, startLevel1);
        timer.start();
    }

    private function placeTitel():void
    {
        titel = new L1Titel();
        addChild(titel);
        titel.x = 275;
        titel.y = 150;
    }

    private function startLevel1(event:TimerEvent):void
    {
        for (counter = 0; counter < aantalSun; counter++)
        {
            sun = new Sun();
            sunArray.push(sun);
            addChild(sun);
            sun.addEventListener(MouseEvent.CLICK, checkSun);
        }

        min = new Min();
        addChild(min);
        min.x = 275;
        min.y = 30;
        min.play();
        min.width = 40;
        min.height = 20;

        timer = new Timer(20000,1);
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, gameOver);
        timer.start();

        menu = new MenuBtn();
        addChild(menu);
        menu.x = 510;
        menu.y = 380;
        menu.addEventListener(MouseEvent.CLICK, gotoHoofdmenu);
    }

    private function checkSun(event:MouseEvent):void
    {
        aantalSun--;

        if (aantalSun == 0)
        {
            wellDone();
            timer.stop();
        }
    }

    public function wellDone():void
    {
        removeChild(menu);
        removeChild(min);

        welldone = new WellDone();
        addChild(welldone);
        welldone.x = 275;
        welldone.y = 150;

        volglevel = new VolgLevel();
        addChild(volglevel);
        volglevel.x = 300;
        volglevel.y = 250;
        volglevel.addEventListener(MouseEvent.CLICK, gotoLevel2);

        hoofdBtn = new HoofdmenuBtn();
        addChild(hoofdBtn);
        hoofdBtn.x = 95;
        hoofdBtn.y = 250;
        hoofdBtn.addEventListener(MouseEvent.CLICK, gotoHoofdmenuW);
    }

    private function gameOver(event:TimerEvent):void
    {
        //timer.stop();

        removeChild(min);
        removeChild(menu);

        for (counter = 0; counter < sunArray.length; counter++)
        {
            removeChild(sunArray[counter]);
        }

        gameover = new GameOver();
        addChild(gameover);
        gameover.x = 275;
        gameover.y = 150;

        opn = new Opnieuw();
        addChild(opn);
        opn.x = 300;
        opn.y = 250;
        opn.addEventListener(MouseEvent.CLICK, level1Opn);

        hoofdBtn = new HoofdmenuBtn();
        addChild(hoofdBtn);
        hoofdBtn.x = 95;
        hoofdBtn.y = 250;
        hoofdBtn.addEventListener(MouseEvent.CLICK, gotoHoofdmenuG);
    }

    private function level1Opn(event:MouseEvent):void
    {
        removeChild(gameover);
        removeChild(opn);
        removeChild(hoofdBtn);
        removeChild(back);

        level1 = new Level1();
        addChild(level1);
    }

    private function gotoHoofdmenu(event:MouseEvent):void
    {
        timer.stop();

        removeChild(min);
        removeChild(menu);
        removeChild(back);

        for (counter = 0; counter < sunArray.length; counter++)
        {
            removeChild(sunArray[counter]);
        }
    }

    private function gotoHoofdmenuW(event:MouseEvent):void
    {
        removeChild(back);
        removeChild(welldone);
        removeChild(hoofdBtn);
        removeChild(volglevel);
    }

    private function gotoHoofdmenuG(event:MouseEvent):void
    {
        removeChild(back);
        removeChild(gameover);
        removeChild(hoofdBtn);
        removeChild(opn);
    }

    private function gotoLevel2(event:MouseEvent):void
    {
        removeChild(back);
        removeChild(volglevel);
        removeChild(hoofdBtn);
        removeChild(welldone);

        level2 = new Level2();
        addChild(level2);
    }

}

}

4

2 回答 2

1

我认为你应该重建/重新设计你的游戏结构。

现在,您的代码做了一些奇怪的事情:

  • 在您的 Main 类中:每次调用函数gotoLevel1时,您都会创建一个新的实例Level1
  • Level1函数的类中,level1Opn您创建另一个“Level1”实例并将其添加到 Level1 中 - 相当混乱。

这不仅仅是小的代码调整——你应该非常显着地重建它。

于 2012-06-14T09:18:52.210 回答
0

似乎您永远不会从菜单中删除 level1 。即使您从级别 1 中删除了所有子级,影片剪辑仍将存在并位于您的菜单顶部。

我建议您阅读本教程,因为它将教您一些有关构建代码的基本技能,以及特定的游戏开发功能(声音、预加载、将内容保存在 cookie 中): http: //gamedev.michaeljameswilliams.com/2008/09 /17/avoider-game-tutorial-1/

于 2012-06-14T09:20:25.703 回答