【问题标题】:Using the Feathers ScreenNavigator with Starling and Signals将 Feathers ScreenNavigator 与 Starling 和 Signals 一起使用
【发布时间】:2014-10-10 02:34:19
【问题描述】:

我是 Flash、Starling 和 Feathers 的新手,我正在给自己上一门速成课程,但我很困惑。 我只是想让我的根八哥类启动我的游戏屏幕。我很抱歉,如果这是noobish。我真的很想明白。

我不确定是什么调度 FeathersEventType.INITIALIZE 并且我无法手动调度它。任何指向正确方向的指针将不胜感激。

在我的 Main.as(我的文档类)中,我实例化了 starling,等待创建 Root,然后调用它的 Start 函数(在如何显示初始背景的示例中看到了这一点,不确定它是否最佳实践)。

this.mStarling = new Starling(Root, this.stage, viewPort);
... //set background from embed
mStarling.addEventListener(starling.events.Event.ROOT_CREATED, 
            function(event:Object, app:Root):void
            {
                mStarling.removeEventListener(starling.events.Event.ROOT_CREATED, arguments.callee);
                removeChild(background);
                background = null;

                var bgTexture:Texture = Texture.fromEmbeddedAsset(
                    backgroundClass, false, false);
                //app.start(bgTexture, assets);
                app.start(bgTexture, assets)  // call the START on my root class
                        mStarling.start();
            });

这是我的根类(这是传递给 Starling 的根类)

public function Root() 
    {
        if (verbose)    trace(this + "Root(" + arguments);
        super();
        this.addEventListener(FeathersEventType.INITIALIZE, initializeHandler);
    }

 // this is not being called
private function initializeHandler(e:Event):void 
    {
        this._navigator.addScreen(GAME_SCREEN, new ScreenNavigatorItem(GameScreen, 
        {
            complete: MAIN_MENU
        }));
    }

public function start(background:Texture, assets:AssetManager):void
    {
        sAssets = assets;  // assets loaded on document class
        addChild(new Image(background));  // passed from doc class

        this._navigator = new ScreenNavigator();
        this.addChild(this._navigator);

        var progressBar:ProgressBar = new ProgressBar(300, 20);
        progressBar.x = (background.width  - progressBar.width)  / 2;
        progressBar.y = (background.height - progressBar.height) / 2;
        progressBar.y = background.height * 0.85;
        addChild(progressBar);

        // Progress bar while assets load
        assets.loadQueue(function onProgress(ratio:Number):void
        {
            progressBar.ratio = ratio;

            if (ratio == 1)
                Starling.juggler.delayCall(function():void
                {
                    gameScreen = new GameScreen();
                                trace("got this far" + gameScreen);
                    gameScreen.GAME_OVER.add(gotoGameOverScreen);

                    gameOverScreen = new GameOverScreen();
                    gameOverScreen.PLAY_AGAIN.add(gotoGameScreen);

                    progressBar.removeFromParent(true);

                    // This is where I'd like the GAME_SCREEN to show.

                    // now would be a good time for a clean-up 
                    System.pauseForGCIfCollectionImminent(0);
                    System.gc();
                }, 0.15);
        });

【问题讨论】:

    标签: actionscript-3 flash starling-framework


    【解决方案1】:

    这是我的根类的一部分

      public function start(background:Texture, assets:AssetManager):void
            {
            stageW=  int(stage.stageWidth);
            stageH = int(stage.stageHeight);
    
    
            sAssets = assets;
    
            bgIma=new Image(background);
            bgIma.height=g.stageH * 0.4;
            bgIma.scaleX=bgIma.scaleY;
    
            bgIma.x=(g.stageW-bgIma.width)>>1;
            bgIma.y=(g.stageH-bgIma.height)>>1;
    
            addChild(bgIma);
    
    
            var progressBar:ProgressBar = new ProgressBar(175, 20);
            progressBar.x = (g.stageW  - progressBar.width)  >> 1;
            progressBar.y = (g.stageH - progressBar.height) >> 1;
            progressBar.y = g.stageH * 0.8;
            addChild(progressBar);
    
    
            assets.loadQueue(function onProgress(ratio:Number):void
            {
                progressBar.ratio = ratio;
    
                if (ratio == 1)
                    Starling.juggler.delayCall(function():void
                    {
                        progressBar.removeFromParent(true);
                        removeChild(bgIma);
                        bgIma=null;
    
                        addedToStageHandler();
                        addSounds();
    
                        System.pauseForGCIfCollectionImminent(0);
                        System.gc();
                    }, 0.15);
            });
        }
    
    
    
    
    
        protected function addedToStageHandler(event:starling.events.Event=null):void
        {
    
            this._navigator = new ScreenNavigator();
            _navigator.autoSizeMode = ScreenNavigator.AUTO_SIZE_MODE_CONTENT; 
            this.addChild( this._navigator );
    
            this._transitionManager = new ScreenFadeTransitionManager(_navigator);
    
            this._navigator.addScreen( "Fluocode", new ScreenNavigatorItem(Fluocode));
            this._navigator.addScreen( "Main", new ScreenNavigatorItem(AppMain));
    
           this._navigator.showScreen("Fluocode");
    
            this._transitionManager.duration = 0.5;
            this._transitionManager.ease = Transitions.EASE_IN;
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多