前往
大廳
主題

【RMMV】變格推理開發日誌01:在隊伍選單新增指令

脆脆的餅乾 | 2024-02-06 03:50:34 | 巴幣 0 | 人氣 42

第一篇開發日誌決定來簡單記錄一下嘗試用JS實作自製功能的過程,希望這樣可以讓之後的我比較好回憶做法,或者是怎麼找教學然後把作法統合到一起(´・ω・))

變格推理是我第一款用MV、跟負責美術的朋友合作而且有明確目標的RM遊戲,沒意外的話這個開發日誌系列會以遊戲做完作結。

目標

如題,主要是想透過隊伍選單的指令打開自製視窗,玩家按下取消鍵後可以關閉,回到隊伍選單。
之後想做成類似文字版圖鑑的筆記功能,讓玩家經歷劇情後可以有地方翻看專有名詞、人物介紹和選擇想標註的詞彙幫助思考之類的。

實作過程

考慮到我自己對腳本不熟,所以第一步就是找教學;這次從找資料到實作的過程中參考了三篇,在食夢大的教學理解在遊戲裡加入視窗需要什麼函式,路漫行大的教學裡修改標題視窗的例子觀察RM實際調用Window和Scene的樣子與如何在視窗裡顯示文字,最後是耶黑大的影片,透過在隊伍選單加入讀檔指令來了解RM的隊伍選單怎麼讓選單指令跟視窗產生連動。

這期間因為是東看西看教學把語法東拼西湊起來的,所以有幾度在測試時發生不知原因的錯誤,甚至想說是不是上RM版求救或是找腳本還比較快,但好歹還是把一個視窗給弄出來了,當看到它出現在畫面上的時候還有種莫名的感動(?

成果


程式
//建立指令視窗
Scene_Menu.prototype.createCommandWindow = function() {
    this._commandWindow = new Window_MenuCommand(0, 0);
    this._commandWindow.setHandler('item',      this.commandItem.bind(this));
    this._commandWindow.setHandler('skill',     this.commandPersonal.bind(this));
    this._commandWindow.setHandler('equip',     this.commandPersonal.bind(this));
    this._commandWindow.setHandler('status',    this.commandPersonal.bind(this));
    this._commandWindow.setHandler('note',      this.commandNote.bind(this));
    this._commandWindow.setHandler('formation', this.commandFormation.bind(this));
    this._commandWindow.setHandler('options',   this.commandOptions.bind(this));
    this._commandWindow.setHandler('save',      this.commandSave.bind(this));
    this._commandWindow.setHandler('gameEnd',   this.commandGameEnd.bind(this));
    this._commandWindow.setHandler('cancel',    this.popScene.bind(this));
    this.addWindow(this._commandWindow);
};

Scene_Menu.prototype.commandNote=function(){
    SceneManager.push(Scene_Note);
}

//在視窗清單上新增指令
Window_MenuCommand.prototype.makeCommandList = function() {
    this.addMainCommands();
    this.addNoteCommand();
    this.addFormationCommand();
    this.addOptionsCommand();
    this.addSaveCommand();
    this.addGameEndCommand();
};


Window_MenuCommand.prototype.addNoteCommand=function(){
    this.addCommand('筆記','note',true);
}

//Window_Note

function Window_Note() {
    this.initialize.apply(this, arguments);
}

//將MV內建的Window屬性繼承到筆記視窗Window_Note上
Window_Note.prototype=Object.create(Window_Selectable.prototype);


Window_Note.prototype.initialize=function(x,y,width,height){
    Window_Selectable.prototype.initialize.call(this,x,y,width,height);
    this.refresh();
}

Window_Note.prototype.refresh = function() {
    var x = this.textPadding();  //設定變數x
    var width = this.contents.width - this.textPadding() * 2;  //設定變數width
    this.contents.clear();  //清空畫面
    this.drawText(this.value(),x,0,width);    //顯示內容
}

Window_Note.prototype.value=function(){
    return "筆記";
}

Window_Note.prototype.open = function() {
    this.refresh();
    Window_Base.prototype.open.call(this);
};


//Scene_Note

function Scene_Note() {
    this.initialize.apply(this, arguments);
}

Scene_Note.prototype=Object.create(Scene_MenuBase.prototype);
Scene_Note.prototype.constructor=Scene_Note;

Scene_Note.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_Note.prototype.create=function(){
    Scene_MenuBase.prototype.create.call(this);
    this._noteWindow = new Window_Note(300,240,1280,720);
    this.addWindow(this._noteWindow);
}

Scene_Note.prototype.update = function() {
    if (Input.isTriggered('escape') || Input.isTriggered('cancel')) {
        this._noteWindow.hide();
        SceneManager.goto(Scene_Menu);
    }
};

創作回應

更多創作