2014-10-10 61 views
0

我是新來的Flash,Starling和羽毛,並給我自己一種速成課程,但我感到困惑。 我只是想讓我的根椋鳥課程啓動我的遊戲屏幕。我很抱歉,如果這是不好的。我真的很想明白。使用羽毛ScreenNavigator與Starling和信號

我不確定調度FeathersEventType.INITIALIZE是什麼,我無法手動調度它。任何正確的方向指針將不勝感激。

在我的Main.as(我的文檔類)中,我實例化starling,等待Root被創建,然後調用它的Start函數(在一個如何顯示初始背景的例子中看到這個,不知道if這是最佳實踐)。

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(); 
      }); 

這裏是我的根類(這是傳遞給椋鳥的根類)

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); 
     }); 

回答

0

這是我的根類的一部分

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; 

    }