OSDN Git Service

pauseStageの改造。
authorttwilb <ttwilb@users.sourceforge.jp>
Tue, 3 Sep 2013 14:21:02 +0000 (23:21 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Tue, 3 Sep 2013 14:21:02 +0000 (23:21 +0900)
pauseStage(func, initFunc)
func : ステージ停止中にtick毎に実行される。
initFunc : もしpauseStageした時点ですでにpauseStageされているのであれば、それを待ったうえで再びpauseStageできるようになった時にこの関数が呼ばれる。(省略するとこの場合に例外が発生)

www/corelib/core.js

index 90e4779..23bd7ed 100644 (file)
@@ -101,8 +101,11 @@ function GameManager(parent, debugTextName){
        this.runningWidgets = [];
        //タイマーカウントを初期化
        this.tickCount = 0;
-       // pauseStage()が呼ばれたときにnullじゃなくなる
-       this.stagePausedFunction = null;
+       
+       // pauseStage()関連の配列。
+       this.stagePaused = false;
+       this.stagePausedFunctions = [];
+       this.stagePausedInitFunctions = [];
        
        this.backgroundMusic = null;
 
@@ -123,7 +126,7 @@ GameManager.prototype = {
                //各オブジェクトの単位時間ごとの動作と再描画を行う
                //単位時間ごとの動作
                this.tickCount++;
-               if(this.stagePausedFunction == null){
+               if(!this.stagePaused){
                        //ポーズしていなければ更新処理
                        if(this.runningStage){
                                //ステージ
@@ -131,7 +134,7 @@ GameManager.prototype = {
                        }
                }
                // runningStage.timerTick() 内でpauseStage()された時、ここで再度判定しないとWidghetのtickが実行されてしまう
-               if(this.stagePausedFunction == null){
+               if(!this.stagePaused){
                        //ウィジェット
                        for(var i = 0; i < this.runningWidgets.length; i++){
                                var w = this.runningWidgets[i];
@@ -143,7 +146,7 @@ GameManager.prototype = {
                        }
                } else{
                        //ポーズしているならば処理関数を実行
-                       this.stagePausedFunction();
+                       this.stagePausedFunctions[0]();
                }
                
                
@@ -212,21 +215,41 @@ GameManager.prototype = {
                }
                
        },
-       pauseStage: function(func){
+       // func : 停止中にtick毎に呼ばれる関数。
+       // initFunc : pauseが可能となった時に呼ばれる関数。指定しないと、その時点でpauseが不可能だったときに例外がおこる。
+       pauseStage: function(func, initFunc){
                //ステージの実行を一時停止する。一時停止中、funcに指定された関数が毎tick毎に呼ばれる
-               if(this.stagePausedFunction == null){
-                       this.stagePausedFunction = func;
+               if(!this.stagePaused){
+                       if(!initFunc) initFunc = null;
+                       this.stagePausedFunctions.push(func);
+                       this.stagePausedInitFunctions.push(initFunc);
+                       this.stagePaused = true;
                        return true;
                } else{
-                       //ステージが一時停止中のfunc()の中から二重にpauseStage()を呼んではいけない
-                       throw "pauseStage calling doubled.";
+                       if(!initFunc)
+                       {
+                               throw "pauseStage calling doubled.";
+                       }else
+                       {
+                               this.stagePausedFunctions.push(func);
+                               this.stagePausedInitFunctions.push(initFunc);
+                               return true;
+                       }
                }
        },
        resumeStage: function(){
                //ステージの実行を再開する
-               if(this.stagePausedFunction != null) {
+               if(this.stagePaused) {
                        //必ずpauseStage()の引数に指定したfunc()の中から呼ばれる・・・はず。
-                       this.stagePausedFunction = null;
+                       this.stagePausedFunctions.splice(0, 1);
+                       this.stagePausedInitFunctions.splice(0, 1);
+                       if(this.stagePausedFunctions.length == 0)
+                       {
+                               this.stagePaused = false;
+                       }else
+                       {
+                               this.stagePausedInitFunctions[0]();
+                       }
                        return true;
                } else{
                        return false;
@@ -246,7 +269,9 @@ GameManager.prototype = {
                        aGameStage.debugCanvas = null;
                        aGameStage.mainContext = null;
                        aGameStage.debugContext = null;
-                       this.stagePausedFunction = null;
+                       this.stagePausedFunctions = [];
+                       this.stagePausedInitFunctions = [];
+                       this.stagePaused = false;
                        
                        //画面上に表示されたすべてのWidgetを解放する
                        for(;this.runningWidgets.length>0;)