如何在不使用as3中的帧的情况下在游戏和菜单之间进行转换?

时间:2013-05-16 08:12:34

标签: actionscript-3 class menu navigation onclicklistener

我简化了此代码以便于阅读

我有一个名为LevelSelect的类,        一类叫做游戏,    还有一个名为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");

    }

1 个答案:

答案 0 :(得分:0)

将舞台视为一张空白的纸张,您可以将其贴在便利贴上。因此,当您开始游戏时,您的纸张是空白的,并在此空白“舞台”上添加便利贴,其中包含您的级别选择屏幕。

您可以通过向舞台添加动画片段或精灵来实现此目的,或者更好地将一个容器添加到您将添加所有其他元素的舞台上(这将使以后更容易,因为您可以删除容器及其中的所有内容也会一次性删除。)

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

  1. 删除纸张上的当前便利贴(即,移除具有等级选择屏幕的容器)。
  2. 放置一个新的便利贴,其中包含玩家点击的等级(即,现在您将另一个容器添加到舞台上,并将新等级的所有元素添加到其中。)
  3. 当用户想要返回级别选择屏幕时,您所做的只是删除当前纸张上的便利贴,并添加包含级别选择屏幕的便利贴。