| 赞 | 58 |
| VIP | |
| 好人卡 | |
| 积分 | 47 |
| 经验 | |
| 最后登录 | 2026-10-1 |
| 在线时间 | 501 小时 |
- 梦石
- 0
- 星屑
- 4716
- 在线时间
- 501 小时
- 注册时间
- 2013-12-7
- 回帖
- 333
 
|
发表于 2019-1-4 10:41:10
|
显示全部楼层
本帖最后由 ekmomo 于 2019-1-4 10:57 编辑
SceneManager起到每帧刷新输入与场景的作用。
这里不贴了,自行查看游戏开始运行时执行的SceneManager.run通过SceneManager.requestUpdate带起的SceneManager.update里面的SceneManager.updateMain。
另外,如果不明白SceneManager.requestUpdate里的requestAnimationFrame的话,推荐百度一下。
下面是Scene.js
- Scene_Map.prototype.updateCallMenu = function() {
- if (this.isMenuEnabled()) {
- if (this.isMenuCalled()) {
- this.menuCalling = true;
- }
- if (this.menuCalling && !$gamePlayer.isMoving()) {
- this.callMenu();
- }
- } else {
- this.menuCalling = false;
- }
- };
复制代码
- Scene_Map.prototype.isMenuCalled = function() {
- return Input.isTriggered('menu') || TouchInput.isCancelled();
- };
复制代码
下面在core.js里
- Input.isTriggered = function(keyName) {
- if (this._isEscapeCompatible(keyName) && this.isTriggered('escape')) {
- return true;
- } else {
- return this._latestButton === keyName && this._pressedTime === 0;
- }
- };
复制代码
- Input.update = function() {
- this._pollGamepads();
- if (this._currentState[this._latestButton]) {
- this._pressedTime++;
- } else {
- this._latestButton = null;
- }
- for (var name in this._currentState) {
- if (this._currentState[name] && !this._previousState[name]) {
- this._latestButton = name;
- this._pressedTime = 0;
- this._date = Date.now();
- }
- this._previousState[name] = this._currentState[name];
- }
- this._updateDirection();
- };
复制代码- Input._onKeyDown = function(event) {
- if (this._shouldPreventDefault(event.keyCode)) {
- event.preventDefault();
- }
- if (event.keyCode === 144) { // Numlock
- this.clear();
- }
- var buttonName = this.keyMapper[event.keyCode];
- if (ResourceHandler.exists() && buttonName === 'ok') {
- ResourceHandler.retry();
- } else if (buttonName) {
- this._currentState[buttonName] = true;
- }
- };
复制代码
- Input.keyMapper = {
- 9: 'tab', // tab
- 13: 'ok', // enter
- 16: 'shift', // shift
- 17: 'control', // control
- 18: 'control', // alt
- 27: 'escape', // escape
- 32: 'ok', // space
- 33: 'pageup', // pageup
- 34: 'pagedown', // pagedown
- 37: 'left', // left arrow
- 38: 'up', // up arrow
- 39: 'right', // right arrow
- 40: 'down', // down arrow
- 45: 'escape', // insert
- 81: 'pageup', // Q
- 87: 'pagedown', // W
- 88: 'escape', // X
- 90: 'ok', // Z
- 96: 'escape', // numpad 0
- 98: 'down', // numpad 2
- 100: 'left', // numpad 4
- 102: 'right', // numpad 6
- 104: 'up', // numpad 8
- 120: 'debug' // F9
- };
复制代码
- Graphics._setupEventHandlers = function() {
- window.addEventListener('resize', this._onWindowResize.bind(this));
- document.addEventListener('keydown', this._onKeyDown.bind(this));
- document.addEventListener('keydown', this._onTouchEnd.bind(this));
- document.addEventListener('mousedown', this._onTouchEnd.bind(this));
- document.addEventListener('touchend', this._onTouchEnd.bind(this));
- };
复制代码
用到的事件和方法一共就这么多,最后一步Scene.prototype.callMenu楼上说了
- Scene_Map.prototype.callMenu = function() {
- SoundManager.playOk();
- SceneManager.push(Scene_Menu);
- Window_MenuCommand.initCommandPosition();
- $gameTemp.clearDestination();
- this._mapNameWindow.hide();
- this._waitCount = 2;
- };
复制代码 |
|