0

我已经简化了这段代码以便于阅读

我有一类叫做 LevelSelect,一类叫做 Game,还有一类叫做 NavButtons。*/

The code below i have added levelSelect MovieClip to the stage and 
added level numbers to level boxes
onclick it goes to my selected level.

public class LevelSelectPage extends Game
{
    public var levelSelectScreen:level_selection;
    public var list:Array;
    // add movieClips to L1,L2 etc...
    public static var Level:String = "No Level Selected";
    public static var shared:SharedObject;


    public function LevelSelectPage( ) 
    {
        setUpLevelSelect(); 
    }

    public function setUpLevelSelect():void
    {
        shared = SharedObject.getLocal("savegame");
        shared.clear(); // remove when game completed
        if (shared.data.level_passed == undefined)
        {
            shared.data.level_passed = 3;
        }
        if (shared.data.playing_level == undefined)
        {
            shared.data.playing_level = "L0";
        } 
        else
        {
            shared.data.playing_level = "L0";
        }

        levelSelectScreen = new level_selection();

        addChild(levelSelectScreen);

        AddMovieClipsForLevels(); 
    }

    public function AddMovieClipsForLevels():void 
    {
        // array of movieClip instances... level pictures.
        list  = [
                        levelSelectScreen.L1,
                        levelSelectScreen.L2,
                        levelSelectScreen.L3
                ];

        list.forEach(setupSquare);  

    }

    public function setupSquare(square:MovieClip, index:int, array:Array):void
    {
        // add numbers on top of level images

        // get numbers of the levels... as index starts from 0, add 1
        var LevelNumber:Number = index + 1;

        // convert number to string
        var imageLevelNumber:String = LevelNumber.toString();
// set textfield     // get childs instance name    
             var     insertlevelNumber:TextField 
            =  square.getChildByName("levelNumberText") as TextField;
        // output text
        insertlevelNumber.text = imageLevelNumber;

    }

    public function onSquareClick(me:MouseEvent):void
    {

        switch(me.currentTarget.name)
        {
            case "L1":   // trace("level 1 was selected");
            // startGame();
            break;  

        }

    }

}
}

public class Game
{
    // imagen a blank screen, it doesn't matter
}

下面的代码 - 我已将导航按钮添加到游戏阶段,单击后退按钮会输出跟踪语句,但我如何再次运行 LevelSelectPage 呢?

public class NavButtons
{
    private var m_NavDisplayIcon:ReferenceArray;
    private var m_stage:Stage;


    public function NavButtons( stage:Stage )
    { 
        // add navigation to stage
        m_stage = stage;

        m_NavDisplayIcon = new ReferenceArray( navDisplayFla );

        var icon:navDisplayFla = new navDisplayFla( );

            icon.x = 5;
            icon.y = 5;

            m_NavDisplayIcon.Add( icon );

            m_stage.addChild( icon );

        // addEventlisteners for backButton, pause game and information

        icon.backIcon.addEventListener(MouseEvent.CLICK,    goBackToLevelSelectPage);
        icon.pauseIcon.addEventListener(MouseEvent.CLICK, pauseGame);
        icon.informationIcon.addEventListener(MouseEvent.CLICK,     showInformation);
    }

    public function goBackToLevelSelectPage( event:MouseEvent ):void
    {

        //var levelSelectScreen:level_selection = new LevelSelectPage();
        //m_stage.addChild(levelSelectScreen);
        trace("you pressed the backButton");

    }
4

1 回答 1

0

把舞台想象成一张白纸,你可以在上面贴便利贴。所以当你开始游戏时,你的纸是空白的,你在这个包含你的关卡选择屏幕的空白“舞台”上添加了一张便利贴。

您可以通过向舞台添加影片剪辑或精灵来完成此操作,或者更好的是向舞台添加一个容器,然后您将向其中添加所有其他元素(这将使以后更容易,因为您可以删除容器并且其中的所有内容都将被删除以及一口气)。

现在,当玩家点击关卡选择屏幕上的按钮时,您需要做的是:

  1. 删除当前在纸上的便利贴(即,删除具有您的级别选择屏幕的容器)。
  2. 放置一个新的便利贴,其中包含玩家单击的关卡(即,现在您将另一个容器添加到舞台,并将新关卡的所有元素添加到其中。)

当用户想要返回关卡选择屏幕时,您只需再次移除当前纸上的便利贴,并添加包含关卡选择屏幕的便利贴。

于 2013-05-16T15:52:20.543 回答