0

私はフラッシュでゲームを作っていますが、私が抱えている問題は、スタートゲームボタンを持つウェルカムスクリーン用のメニューと呼ばれるクラスと、ゲームを初めて実行するときにすべてを実行するエンジンクラスの2つのクラスにあります。このコードによって自動的に表示されるメニュー:

    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 に答える