0

我正在用 Flash 制作游戏,我遇到的问题是有两个类,一个是欢迎屏幕的菜单类,它有一个开始游戏按钮,另一个是引擎类,它在我第一次运行游戏时运行所有东西我设置菜单通过此代码自动出现:

    public var state:int;
    public const MENU:int = 0;
    public const GAME:int = 1;
    // create the variable for the menu
    private var _menu:Menu;

    public var sBg1:ScrollBg;
    public var sBg2:ScrollBg;
    public function Engine(menu:Menu) 
    {

        _menu = menu;
        //we add event listener when the engine is added to the stage
        addEventListener(Event.ADDED_TO_STAGE, onAdded);
    }
    private function onAdded(e:Event):void {
        //then we remove the event listener and initiate the init function
        removeEventListener(Event.ADDED_TO_STAGE, onAdded);

        init();
    }
    private function init():void {
        //the init function set the game state at first to menu and run the drawUI function
        state = MENU;
        drawUI();

    }

    public function drawUI():void 
    {
        //the drawUI function draw the needed elements on stage according to the state of the game
        switch(state){
            case MENU:
                _menu = new Menu();
                addChild(_menu);
                break;
            case GAME:
                sBg1= new ScrollBg();   
                addChild(sBg1);
                sBg1.x = 0;
                sBg1.y = 0;
                //if(contains(_menu)){
                //removeChild(_menu);}

                trace('this the game');
                break;
                    }
    }

我在菜单类中使用以下代码将状态从菜单更改为实际游戏:

    public var start_btn:MovieClip;
    private var _engine:Engine;
    public function Menu() 
    {
        addEventListener(Event.ADDED_TO_STAGE, displayMenu);
    }

    private function displayMenu(e:Event):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, displayMenu);
        start_btn = new startBtn();
        start_btn.x = 100;
        start_btn.y = 200;
        addChild(start_btn);
        start_btn.addEventListener(MouseEvent.CLICK, startGame);
    }

    private function startGame(e:MouseEvent):void 
    {
        start_btn.removeEventListener(MouseEvent.CLICK, startGame);
        _engine = new Engine(this);
        _engine.state = 1;
        _engine.drawUI();
    }

我每次为菜单使用drawUI功能,例如它放置开始按钮和游戏放置背景但由于某种原因我只得到跟踪语句说(这个游戏)但背景没有显示任何线索。

我花了超过 4 个小时试图找出问题所在,但如果有人能帮助我,那我仍然无法解决。

谢谢

4

1 回答 1

0

如果您看到跟踪但屏幕上什么也没有,这很可能是因为 ScrollBg 类没有任何可显示的内容。确保该类中有一些精灵或图像。

于 2012-04-28T04:54:24.643 回答