Project1
标题:
RPG Maker MV 的源码研究 十三
[打印本页]
作者:
沉滞的剑
时间:
2019-8-23 22:53
标题:
RPG Maker MV 的源码研究 十三
Scene_Map算是比较复杂的场景了
目测水上十篇是没问题的
====================================
我们这次先笼统得了解一下整个场景的功能
然后再慢慢逐个分析其具体实现
先是构造函数和create方法
Scene_Map.prototype.initialize = function () {
Scene_Base.prototype.initialize.call(this);
this._waitCount = 0;
// 打开菜单的缓冲帧
this._encounterEffectDuration = 0;
// 遇敌过场持续时间
this._mapLoaded = false;
// 地图加载状态标识
this._touchCount = 0;
// 触摸计时器
// 玩家持续按下鼠标可以引导角色前往当前鼠标的位置(>15帧)
};
Scene_Map.prototype.create = function () {
Scene_Base.prototype.create.call(this);
this._transfer = $gamePlayer.isTransferring();
// 过场标识
// 这个在Scene_Title交接的时候设置为true了
var mapId = this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId();
// 如果是过场, 加载新地图, 否则加载当前地图
DataManager.loadMapData(mapId);
};
复制代码
然后是start方法
Scene_Map.prototype.start = function () {
Scene_Base.prototype.start.call(this);
SceneManager.clearStack();
// 场景管理器清空场景栈
if (this._transfer) {
// 如果是过场
this.fadeInForTransfer();
// 过场淡入效果
this._mapNameWindow.open();
// 地图名字窗口打开
$gameMap.autoplay();
// 自动播放地图音乐
} else if (this.needsFadeIn()) {
// 如果从战斗或者录取记录场景切换回来则进行淡入
this.startFadeIn(this.fadeSpeed(), false);
}
// 设置呼叫菜单状态为false
this.menuCalling = false;
};
复制代码
然后是update方法
Scene_Map.prototype.update = function () {
this.updateDestination();
// 判断玩家输入, 设置角色移动目的
this.updateMainMultiply();
// 更新游戏对象
if (this.isSceneChangeOk()) {
// 更新场景
// 游戏结束/地图切换/遇敌/呼叫菜单
this.updateScene();
} else if (SceneManager.isNextScene(Scene_Battle)) {
// 如果正在进入遇敌场景, 更新遇敌动画效果
this.updateEncounterEffect();
}
// 更新菜单缓冲计数器
this.updateWaitCount();
Scene_Base.prototype.update.call(this);
};
复制代码
其实还有一个中止的生命周期方法会被SceneManager调用
SceneManager.goto = function (sceneClass) {
if (sceneClass) {
this._nextScene = new sceneClass();
}
if (this._scene) {
this._scene.stop(); // 在这里
}
};
复制代码
类似于create和start
stop并不会立刻注销scene, 而是要等到当前的场景完成了手头的任务后才会注销
会触发terminate方法
SceneManager.changeScene = function () {
if (this.isSceneChanging() && !this.isCurrentSceneBusy()) {
if (this._scene) {
this._scene.terminate(); // 在这里
this._scene.detachReservation();
this._previousClass = this._scene.constructor;
}
this._scene = this._nextScene;
if (this._scene) {
this._scene.attachReservation();
this._scene.create();
this._nextScene = null;
this._sceneStarted = false;
this.onSceneCreate();
}
if (this._exiting) {
this.terminate();
}
}
};
复制代码
在Scene_Map里是这个样子的
Scene_Map.prototype.stop = function () {
Scene_Base.prototype.stop.call(this);
// 角色立正
// 嗯 没太搞懂为什么要这么做...
$gamePlayer.straighten();
// 关闭地图名称窗口
this._mapNameWindow.close();
if (this.needsSlowFadeOut()) {
// 缓慢淡出
this.startFadeOut(this.slowFadeSpeed(), false);
} else if (SceneManager.isNextScene(Scene_Map)) {
// 过场淡出
this.fadeOutForTransfer();
} else if (SceneManager.isNextScene(Scene_Battle)) {
// 触发战斗
this.launchBattle();
}
};
// 父类方法
Scene_Base.prototype.stop = function () {
this._active = false;
};
Scene_Map.prototype.terminate = function () {
Scene_Base.prototype.terminate.call(this);
// 如果不是战斗和地图传送则不清空缓存
// 并且创建一个截图作为新场景的背景
if (!SceneManager.isNextScene(Scene_Battle)) {
this._spriteset.update();
this._mapNameWindow.hide();
SceneManager.snapForBackground();
} else {
ImageManager.clearRequest();
}
if (SceneManager.isNextScene(Scene_Map)) {
ImageManager.clearRequest();
}
// 清理放大/缩小效果
$gameScreen.clearZoom();
// 清理可显示对象
this.removeChild(this._fadeSprite);
this.removeChild(this._mapNameWindow);
this.removeChild(this._windowLayer);
this.removeChild(this._spriteset);
};
复制代码
====================================
这次作为一个新场景的开篇就到这里为止吧,
虽然有点少但是一篇保证一个主题吧
越来越短了 (得意
作者:
jokefeng
时间:
2019-8-25 15:49
大佬觉得MV游戏时长久了后,内存占比过大导致闪退的死机的,大可有思路解决啊?
作者:
kklt
时间:
2019-8-25 20:55
不喜欢js,动辄就xxx.xxxx.xxxx.xxxxx.xxxx.xxx.xx.xxx.xx.xxx.xx.x.x.x.x.x.x.x.x.xx.x.xx.x.x.xx.xx..x..x..x.x.x...x.x.x
继承也麻烦的要si
也可能只是我不习惯而已吧哈哈
作者:
循环往复的时间
时间:
2024-4-5 16:45
大佬写的好啊
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1