解説/中級編

シナリオ操作

new Theater({
  img: [
    "img/sample1.gif",
    "img/sample2.gif",
    "img/sample3.gif"
  ],
  scenario: [
    function(){
      this.act({
        img: "img/sample1.gif",
        msg: "シナリオ操作テスト開始。"
      });
    },
    function(){
      this.speak("サブシナリオ開始前。pushメソッドでサブシナリオを設定します・・・");
    },
    function(){
      this.push(sub);
      this.keep();
    },
    function(){
      this.speak("メインシナリオに復帰しました。");
    },
    function(){
      this.speak("画像切り替えを繰り返します。");
      this.loop(2, [
        function(){
          this.appear("img/sample2.gif");
        },
        function(){
          this.appear("img/sample3.gif");
        }
      ]);
    },
    function(){
      this.act({
        img: "img/sample1.gif",
        msg: "3からカウントダウンします"
      });
      return false;
    },
    function(){
      var count;
      this.loop([
        function(){ //初期処理関数
          count = 3;
        },
        function(result){ //継続条件判定関数
          return (!result && count >= 0);
        },
        function(result){ //繰り返し毎処理関数
          count--;
          return result;
        },
      ], [
        function(){
          this.speak("カウント: " + count);
        },
        function(){
          if(count == 3){
            this.confirm("中止しますか?");
          }else{
            this.keep();
            return false;
          }
        }
      ]);
      this.keep();
    },
    function(){
      this.speak("シナリオ操作テスト終了。");
    }
  ]
});

var sub = [
  function(){
    this.speak("サブシナリオ開始。");
  },
  function(){
    this.speak("操作を選択してください。");
  },
  function(){
    this.choice(["retake", "skip", "repeat", "back", "reset"]);
  },
  function(result){
    var str = result + "が選択されました。"
    switch(result){
      case "retake":
        str += "このサブシナリオの先頭に戻ります・・・";
        this.retake();
        break;
      case "skip":
        str += "メインシナリオに復帰します・・・";
        this.skip();
        break;
      case "repeat":
        str += "このシナリオ関数を繰り返します・・・※「はじめから」ボタンで戻ってください。";
        this.repeat();
        break;
      case "back":
        str += "一つ前のシナリオ関数に戻ります・・・";
        this.back();
        break;
      case "reset":
        str += "メインシナリオの先頭に戻ります・・・";
        this.reset();
        break;
    }
    this.speak(str);
    return result;
  },
  function(result){
    this.speak("サブシナリオ終了。");
  }
];

サブシナリオの選択ダウンロードと実行

画像の選択ダウンロード

【test.htm】
new Theater({
  img: [
    "img/sample1.gif"
  ],
  scenario: [
    function(){
      this.act({
        img: "img/sample1.gif",
        msg: "テスト開始。"
      });
    },
    function(){
      this.speak("クリックすると別ファイルを読み込んでサブシナリオを開始します・・・");
    },
    function(){
      this.read("sub.js");
      this.playCold("sub");
    },
    function(){
      this.act({
        img: "img/sample1.gif",
        msg: "元のファイルのメインシナリオに復帰しました。"
      });
    },    
    function(){
      this.speak("テスト終了。");
    }
  ]
});
【sub.js】
var sub = [
  function(){
    this.preload([
      "img/sample2.gif",
      "img/sample3.gif"
    ]);
    this.speak("別ファイルのサブシナリオ開始。同時に画像の先読みをしています。");
  },
  function(){
    this.act({
      img: "img/sample2.gif",
      msg: "ここは別ファイルです。"
    });
  },
  function(){
    this.act({
      img: "img/sample3.gif",
      msg: "別ファイルのサブシナリオを終了します"
    });
  }
];

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS