RPGツクールMVでWindow_HorzCommandの使い方のまとめ
ツクールMVにはWindow_HorzCommand
というクラスが用意されている。
Window_Command
と非常によく似た作りのクラスであり、使い方はほぼ同じ。
Window_HorzCommand の使い方
Window_Comamnd
とほぼ同じ。
違いは、numVisibleRows
, maxCols
といったメソッドが指定していることか。
class Window_SampleHorz extends Window_HorzCommand {
// 選択肢を設定する。
makeCommandList() {
this.addCommand('はい', 'yes');
this.addCommand('いいえ', 'no');
}
/**
* Windowのwidthを指定できる。(option)
*/
windowWidth() {
return 240;
};
// 行の数。default: 1
numVisibleRows() {
return 1;
};
// 1行ごとの選択肢の数 default: 4
maxCols() {
return 4;
};
// 各選択肢の幅寄せ default: center。left とか right とか指定できる。
itemTextAlign() {
return 'center';
};
}
使い方は、Window_Command
とほぼ同じ。
Scene_MenuBase
を継承したSceneクラスを用意して、そこに定義していく。
class Scene_Sample extends Scene_MenuBase {
create(){
super.create();
// x: 10 y: 50 の位置にwindowを作成する。
this._cancelConfirmWindow = new Window_SampleHorz(10, 50);
// setHandlerでメニューが選択された時の挙動を指定する。
this._cancelConfirmWindow.setHandler('yes', this.onCancelConfirmYes.bind(this));
this._cancelConfirmWindow.setHandler('no', this.onCancelConfirmNo.bind(this));
this._cancelConfirmWindow.setHandler('cancel', this.onCancelConfirmNo.bind(this));
this.addWindow(this._cancelConfirmWindow);
}
}
また、cancel
というシンボルの設定もしているが、これは右クリックをした時などの挙動を指定できるもの。
およそ、handlerで呼びだす関数でやることは何かしらの処理をした後に、あるwindowは閉じてあるwindowは開くといった 行為になる。
onCancelConfirmNo() {
this._cancelConfirmWindow.close();
this._questListWindow.open();
this._questListWindow.activate();
// メニューから抜け出す時など
SceneManager.pop();
}
他のWindowクラスとの比較
基本的に選択肢を作成する場合はWindow_Command
クラスを使い、
横長の選択肢を作りたい場合は、Window_HorzCommand
となるだろう。
使いみちとしては、メニュー画面で使うことになる。