RPGツクールMVでスクリプトからマップ移動をするためのメモ
自作のプラグインからマップ移動をしたいときがあるので、そのメモを残す。
マップ移動の方法
$gamePlayer.reserveTransfer()
と$gamePlayer.requestMapReload()
を使えば良い。
// マップ移動の実行
$gamePlayer.reserveTransfer(questData.mapId, questData.mapX, questData.mapY, 2, 0);
$gamePlayer.requestMapReload();
// 現在のシーンが、Scene_Map ではない場合は以下も追加する。
SceneManager.goto(Scene_Map);
多くの場合はプラグインコマンドとして実装することになるだろう。
const _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
switch (command) {
case 'クエストマップに移動':
// 現在選択中のクエストのマップに移動
if ($questManager.isQuestActive()) {
const currentQuestId = $questManager.getCurrentQuest();
const questData = $questManager.getQuestData(currentQuestId);
// マップ移動の実行
$gamePlayer.reserveTransfer(questData.mapId, questData.mapX, questData.mapY, 2, 0);
$gamePlayer.requestMapReload();
// SceneManager.goto(Scene_Map);
}
break;
}
};
それぞれのメソッドの説明
$gamePlayer.reserveTransfer メソッド
$gamePlayer.reserveTransfer(マップID, x座標, y座標, 向き, フェード)
向き
テンキーの矢印に対応。 2 にするのがよいかも。
値 | 向き |
---|---|
0 | そのまま |
2 | 下 |
4 | 左 |
6 | 右 |
8 | 上 |
フェード
これは 0 になることが多いか?
値 | フェードタイプ |
---|---|
0 | 黒フェード |
1 | 白フェード |
2 | なし |
$gamePlayer.requestMapReload メソッド
コアエンジンが、マップのリロードをする準備をするためのメソッド。
こいつを使うことで、コアエンジン側がマップのリロードを完璧にやってくれる。
(equestMapReload
メソッドを使わないと、マップに移動はするもののプレイヤーの操作不能という悲しいことが起こる。)
実装は以下のようになっている。
Game_Player.prototype.requestMapReload = function() {
this._needsMapReload = true;
};