扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 168|回复: 0

[转载发布] 鼠标触摸增强

[复制链接]
累计送礼:
0 个
累计收礼:
0 个
  • TA的每日心情
    开心
    2025-2-4 02:05
  • 签到天数: 110 天

    连续签到: 2 天

    [LV.6]常住居民II

    2327

    主题

    395

    回帖

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    6
    卡币
    10465
    OK点
    16
    推广点
    0
    同能卷
    0
    积分
    13215

    灌水之王

    发表于 2024-2-13 12:26:17 | 显示全部楼层 |阅读模式
    之前练手用的,因为覆盖了很多函数,感觉会冲突的哗啦哗啦
    默认工程可以用,用了YEP的也可以用,不过写的比较乱,主要是分享一下想法

    update 2016/01/16:
    - 修正交通工具无效的问题

    实现功能:
    1 鼠标: 将判定点从按下改为单击(按下再弹起)
    2 鼠标: 修改移动事件的判定
    3 鼠标: 选择窗口鼠标滑动改变选项,点击即是确认
    4 鼠标: 地图上,点击鼠标表示移动到点,会触发事件。长按鼠标表示向点移动,不会触发事件和目的地闪动的动画。鼠标和人物距离远会变为跑动。
    5 触摸: 将判定点从按下改为单击
    6 触摸: 增加向左快速滑动手势,表示返回
    7 触摸: 修正YEP战斗导致chrome触摸无法选中敌人的问题
    8 触摸: 选择窗口取消按住拖动改变当前选项,改为按住拖动滑动页面,点击既是确认
    9 触摸: 地图上,单击手指是移动到点,会触发时间,按住手指表示向点移动,不会触发事件。手指和人物距离远会变为跑动。
    JAVASCRIPT 代码下载
    1. //=============================================================================
    2. // Trentswd Plugins - Touch Event Extend
    3. // TWDP_TouchEventEx.js
    4. //=============================================================================
    5. var Imported = Imported || {};
    6. Imported.TWDP_TouchEventEx = true;
    7. var TWDP = TWDP || {};
    8. TWDP.TEE = TWDP.TEE || {};
    9. //=============================================================================
    10. /*:
    11. * @plugindesc v1.00 Extend the Touch Event
    12. * @author Trentswd
    13. *
    14. * @help
    15. * ============================================================================
    16. * Introduction
    17. * ============================================================================
    18. *
    19. * Don't have time to write this right now, sorry.
    20. *
    21. * ============================================================================
    22. * Plugin Commands
    23. * ============================================================================
    24. *
    25. * Don't have time to write this right now, sorry.
    26. *
    27. */
    28. //=============================================================================
    29. //=============================================================================
    30. // Parameter Variables
    31. //=============================================================================
    32. TWDP.parameters = PluginManager.parameters('TWDP_TouchEventEx');
    33. TWDP.TEE.param = TWDP.TEE.param || {};
    34. function distanceOfTwoPoints(x1, y1, x2, y2) {
    35.   return Math.round(
    36.     Math.sqrt(
    37.       Math.pow(x1 - x2, 2) +
    38.       Math.pow(y1 - y2, 2)
    39.     )
    40.   );
    41. };
    42. (function($) {
    43.   $.backup = $.backup || {};
    44.   //-----------------------------------------------------------------------------
    45.   /**
    46.    * The static class that handles input data from the mouse and touchscreen.
    47.    *
    48.    * @class TouchInput
    49.    */
    50.   TouchInput.clickDelta = 5;
    51.   TouchInput.backGestureSpeedThreshold = 30;
    52.   TouchInput.backGestureDistanceThreshold = 20;
    53.   /**
    54.    * Initializes the touch system.
    55.    *
    56.    * @static
    57.    * @method initialize
    58.    */
    59.   TouchInput.initialize = function() {
    60.     this.clear();
    61.     this._setupEventHandlers();
    62.   };
    63.   /**
    64.    * The wait time of the pseudo key repeat in frames.
    65.    *
    66.    * @static
    67.    * @property keyRepeatWait
    68.    * @type Number
    69.    */
    70.   TouchInput.keyRepeatWait = 24;
    71.   /**
    72.    * The interval of the pseudo key repeat in frames.
    73.    *
    74.    * @static
    75.    * @property keyRepeatInterval
    76.    * @type Number
    77.    */
    78.   TouchInput.keyRepeatInterval = 6;
    79.   /**
    80.    * Clears all the touch data.
    81.    *
    82.    * @static
    83.    * @method clear
    84.    */
    85.   $.backup.TouchInput_clear = TouchInput.clear;
    86.   TouchInput.clear = function() {
    87.       $.backup.TouchInput_clear.call(this);
    88.       this._pressed = {};
    89.       this._pressed.left = {};
    90.       this._pressed.left.isPressed = false;
    91.       this._pressed.left.pressX = 0;
    92.       this._pressed.left.pressY = 0;
    93.       this._pressed.right = {};
    94.       this._pressed.right.isPressed = false;
    95.       this._pressed.right.pressX = 0;
    96.       this._pressed.right.pressY = 0;
    97.       this._pressed.middle = {};
    98.       this._pressed.middle.isPressed = false;
    99.       this._pressed.middle.pressX = 0;
    100.       this._pressed.middle.pressY = 0;
    101.       this._pressed.touch = {};
    102.       this._pressed.touch.isPressed = false;
    103.       this._pressed.touch.pressX = 0;
    104.       this._pressed.touch.pressY = 0;
    105.       this._clicked = {};
    106.       this._clicked.left = {};
    107.       this._clicked.left.isClicked = false;
    108.       this._clicked.left.x = 0;
    109.       this._clicked.left.y = 0;
    110.       this._clicked.right = {};
    111.       this._clicked.right.isClicked = false;
    112.       this._clicked.right.x = 0;
    113.       this._clicked.right.y = 0;
    114.       this._clicked.middle = {};
    115.       this._clicked.middle.isClicked = false;
    116.       this._clicked.middle.x = 0;
    117.       this._clicked.middle.y = 0;
    118.       this._clicked.touch = {};
    119.       this._clicked.touch.isClicked = false;
    120.       this._clicked.touch.x = 0;
    121.       this._clicked.touch.y = 0;
    122.       this._pressed.left.time = 0;
    123.       this._pressed.right.time = 0;
    124.       this._pressed.middle.time = 0;
    125.       this._pressed.touch.time = 0;
    126.       this._events._clicked = {};
    127.       this._events._clicked.left = {};
    128.       this._events._clicked.left.isClicked = false;
    129.       this._events._clicked.left.x = 0;
    130.       this._events._clicked.left.y = 0;
    131.       this._events._clicked.right = {};
    132.       this._events._clicked.right.isClicked = false;
    133.       this._events._clicked.right.x = 0;
    134.       this._events._clicked.right.y = 0;
    135.       this._events._clicked.middle = {};
    136.       this._events._clicked.middle.isClicked = false;
    137.       this._events._clicked.middle.x = 0;
    138.       this._events._clicked.middle.y = 0;
    139.       this._events._clicked.touch = {};
    140.       this._events._clicked.touch.isClicked = false;
    141.       this._events._clicked.touch.x = 0;
    142.       this._events._clicked.touch.y = 0;
    143.       this._events._pressed = {};
    144.       this._events._pressed.left = {};
    145.       this._events._pressed.left.isPressed = false;
    146.       this._events._pressed.left.pressX = 0;
    147.       this._events._pressed.left.pressY = 0;
    148.       this._events._pressed.right = {};
    149.       this._events._pressed.right.isPressed = false;
    150.       this._events._pressed.right.pressX = 0;
    151.       this._events._pressed.right.pressY = 0;
    152.       this._events._pressed.middle = {};
    153.       this._events._pressed.middle.isPressed = false;
    154.       this._events._pressed.middle.pressX = 0;
    155.       this._events._pressed.middle.pressY = 0;
    156.       this._events._pressed.touch = {};
    157.       this._events._pressed.touch.isPressed = false;
    158.       this._events._pressed.touch.pressX = 0;
    159.       this._events._pressed.touch.pressY = 0;
    160.       this.touchScroll = {};
    161.       this.touchScroll.x = 0;
    162.       this.touchScroll.y = 0;
    163.       this._events.touchScroll = {};
    164.       this._events.touchScroll.x = 0;
    165.       this._events.touchScroll.y = 0;
    166.     }
    167.     /**
    168.      * Updates the touch data.
    169.      *
    170.      * @static
    171.      * @method update
    172.      */
    173.   $.backup.TouchInput_update = TouchInput.update;
    174.   TouchInput.update = function() {
    175.     $.backup.TouchInput_update.call(this);
    176.     this._pressed.left.isPressed = this._events._pressed.left.isPressed;
    177.     this._pressed.left.pressX = this._events._pressed.left.pressX;
    178.     this._pressed.left.pressY = this._events._pressed.left.pressY;
    179.     this._pressed.right.isPressed = this._events._pressed.right.isPressed;
    180.     this._pressed.right.pressX = this._events._pressed.right.pressX;
    181.     this._pressed.right.pressY = this._events._pressed.right.pressY;
    182.     this._pressed.middle.isPressed = this._events._pressed.middle.isPressed;
    183.     this._pressed.middle.pressX = this._events._pressed.middle.pressX;
    184.     this._pressed.middle.pressY = this._events._pressed.middle.pressY;
    185.     this._pressed.touch.isPressed = this._events._pressed.touch.isPressed;
    186.     this._pressed.touch.pressX = this._events._pressed.touch.pressX;
    187.     this._pressed.touch.pressY = this._events._pressed.touch.pressY;
    188.     if (this._pressed.left.isPressed) {
    189.       this._pressed.left.time++;
    190.     } else {
    191.       this._pressed.left.time = 0;
    192.     }
    193.     if (this._pressed.right.isPressed) {
    194.       this._pressed.right.time++;
    195.     } else {
    196.       this._pressed.right.time = 0;
    197.     }
    198.     if (this._pressed.middle.isPressed) {
    199.       this._pressed.middle.time++;
    200.     } else {
    201.       this._pressed.middle.time = 0;
    202.     }
    203.     if (this._pressed.touch.isPressed) {
    204.       this._pressed.touch.time++;
    205.     } else {
    206.       this._pressed.touch.time = 0;
    207.     }
    208.     this._clicked.left.isClicked = this._events._clicked.left.isClicked;
    209.     this._clicked.left.x = this._events._clicked.left.x;
    210.     this._clicked.left.y = this._events._clicked.left.y;
    211.     this._clicked.right.isClicked = this._events._clicked.right.isClicked;
    212.     this._clicked.right.x = this._events._clicked.right.x;
    213.     this._clicked.right.y = this._events._clicked.right.y;
    214.     this._clicked.middle.isClicked = this._events._clicked.middle.isClicked;
    215.     this._clicked.middle.x = this._events._clicked.middle.x;
    216.     this._clicked.middle.y = this._events._clicked.middle.y;
    217.     this._clicked.touch.isClicked = this._events._clicked.touch.isClicked;
    218.     this._clicked.touch.x = this._events._clicked.touch.x;
    219.     this._clicked.touch.y = this._events._clicked.touch.y;
    220.     this._events._clicked.left.isClicked = false;
    221.     this._events._clicked.left.x = 0;
    222.     this._events._clicked.left.y = 0;
    223.     this._events._clicked.right.isClicked = false;
    224.     this._events._clicked.right.x = 0;
    225.     this._events._clicked.right.y = 0;
    226.     this._events._clicked.middle.isClicked = false;
    227.     this._events._clicked.middle.x = 0;
    228.     this._events._clicked.middle.y = 0;
    229.     this._events._clicked.touch.isClicked = false;
    230.     this._events._clicked.touch.x = 0;
    231.     this._events._clicked.touch.y = 0;
    232.     this.touchScroll.x = this._events.touchScroll.x;
    233.     this.touchScroll.y = this._events.touchScroll.y;
    234.     this._events.touchScroll.x = 0;
    235.     this._events.touchScroll.y = 0;
    236.   };
    237.   TouchInput.judgePressed = function(button) {
    238.     return this._pressed[button].isPressed;
    239.   }
    240.   TouchInput.judgeClicked = function(button) {
    241.     return this._clicked[button].isClicked;
    242.   }
    243.   TouchInput.judgeLongPressed = function(button, time) {
    244.     if (time === undefined) {
    245.       time = this.keyRepeatWait
    246.     }
    247.     if (this.judgePressed(button)) {
    248.       return this._pressed[button].time >= time;
    249.     }
    250.     return false;
    251.   }
    252.   /**
    253.    * @static
    254.    * @method _onMouseDown
    255.    * @param {MouseEvent} event
    256.    * @private
    257.    */
    258.   TouchInput._onMouseDown = function(event) {
    259.     if (event.button === 0) {
    260.       this._onLeftButtonDown(event);
    261.     } else if (event.button === 1) {
    262.       this._onMiddleButtonDown(event);
    263.     } else if (event.button === 2) {
    264.       this._onRightButtonDown(event);
    265.     }
    266.     this._date = Date.now();
    267.   };
    268.   /**
    269.    * @static
    270.    * @method _onLeftButtonDown
    271.    * @param {MouseEvent} event
    272.    * @private
    273.    */
    274.   TouchInput._onLeftButtonDown = function(event) {
    275.     var x = Graphics.pageToCanvasX(event.pageX);
    276.     var y = Graphics.pageToCanvasY(event.pageY);
    277.     if (Graphics.isInsideCanvas(x, y)) {
    278.       this._mousePressed = true;
    279.       this._pressedTime = 0;
    280.       this._events._pressed.left.isPressed = true;
    281.       this._events._pressed.left.pressX = x;
    282.       this._events._pressed.left.pressY = y;
    283.       this._onTrigger(x, y);
    284.     }
    285.   };
    286.   /**
    287.    * @static
    288.    * @method _onMiddleButtonDown
    289.    * @param {MouseEvent} event
    290.    * @private
    291.    */
    292.   TouchInput._onMiddleButtonDown = function(event) {
    293.     var x = Graphics.pageToCanvasX(event.pageX);
    294.     var y = Graphics.pageToCanvasY(event.pageY);
    295.     if (Graphics.isInsideCanvas(x, y)) {
    296.       this._events._pressed.middle.isPressed = true;
    297.       this._events._pressed.middle.pressX = x;
    298.       this._events._pressed.middle.pressY = y;
    299.     }
    300.   };
    301.   /**
    302.    * @static
    303.    * @method _onRightButtonDown
    304.    * @param {MouseEvent} event
    305.    * @private
    306.    */
    307.   TouchInput._onRightButtonDown = function(event) {
    308.     var x = Graphics.pageToCanvasX(event.pageX);
    309.     var y = Graphics.pageToCanvasY(event.pageY);
    310.     if (Graphics.isInsideCanvas(x, y)) {
    311.       this._events._pressed.right.isPressed = true;
    312.       this._events._pressed.right.pressX = x;
    313.       this._events._pressed.right.pressY = y;
    314.       //this._onCancel(x, y);
    315.     }
    316.   };
    317.   /**
    318.    * @static
    319.    * @method _onMouseMove
    320.    * @param {MouseEvent} event
    321.    * @private
    322.    */
    323.   $.backup.TouchInput_onMouseMove = TouchInput._onMouseMove;
    324.   TouchInput._onMouseMove = function(event) {
    325.     $.backup.TouchInput_onMouseMove.call(this, event);
    326.     var x = Graphics.pageToCanvasX(event.pageX);
    327.     var y = Graphics.pageToCanvasY(event.pageY);
    328.     this._onMove(x, y);
    329.   };
    330.   TouchInput._onClick = function(x, y, button) {
    331.     if (button === 0) {
    332.       if (this._clicked.left.cancelNext) {
    333.         this._clicked.left.cancelNext = false;
    334.         return;
    335.       }
    336.       this._events._clicked.left.isClicked = true;
    337.       this._events._clicked.left.x = x;
    338.       this._events._clicked.left.y = y;
    339.     } else if (button === 1) {
    340.       if (this._clicked.right.cancelNext) {
    341.         this._clicked.right.cancelNext = false;
    342.         return;
    343.       }
    344.       this._events._clicked.right.isClicked = true;
    345.       this._events._clicked.right.x = x;
    346.       this._events._clicked.right.y = y;
    347.       this._onCancel(x, y);
    348.     } else if (button === 2) {
    349.       if (this._clicked.middle.cancelNext) {
    350.         this._clicked.middle.cancelNext = false;
    351.         return;
    352.       }
    353.       this._events._clicked.middle.isClicked = true;
    354.       this._events._clicked.middle.x = x;
    355.       this._events._clicked.middle.y = y;
    356.     } else if (button === 'touch') {
    357.       if (this._clicked.touch.cancelNext) {
    358.         this._clicked.touch.cancelNext = false;
    359.         return;
    360.       }
    361.       this._events._clicked.touch.isClicked = true;
    362.       this._events._clicked.touch.x = x;
    363.       this._events._clicked.touch.y = y;
    364.     }
    365.   }
    366.   TouchInput.cancelNextClick = function(button) {
    367.     this._clicked[button].cancelNext = true;
    368.   }
    369.   TouchInput._onLeftButtonUp = function(event) {
    370.     var x = Graphics.pageToCanvasX(event.pageX);
    371.     var y = Graphics.pageToCanvasY(event.pageY);
    372.     if (Graphics.isInsideCanvas(x, y)) {
    373.       this._events._pressed.left.isPressed = false;
    374.       var distance = distanceOfTwoPoints(this._pressed.left.pressX, this._pressed.left.pressY,
    375.         x, y)
    376.       if (distance  TouchInput.backGestureDistanceThreshold) {
    377.         return true;
    378.       }
    379.     }
    380.     return false;
    381.   };
    382.   /**
    383.    * @static
    384.    * @method _onTouchCancel
    385.    * @param {TouchEvent} event
    386.    * @private
    387.    */
    388.   TouchInput._onTouchCancel = function(event) {
    389.     this._screenPressed = false;
    390.   };
    391.   /**
    392.    * @static
    393.    * @method _onPointerDown
    394.    * @param {PointerEvent} event
    395.    * @private
    396.    */
    397.   TouchInput._onPointerDown = function(event) {
    398.     if (event.pointerType === 'touch' && !event.isPrimary) {
    399.       var x = Graphics.pageToCanvasX(event.pageX);
    400.       var y = Graphics.pageToCanvasY(event.pageY);
    401.       if (Graphics.isInsideCanvas(x, y)) {
    402.         // For Microsoft Edge
    403.         this._onCancel(x, y);
    404.         event.preventDefault();
    405.       }
    406.     }
    407.   };
    408.   /**
    409.    * @static
    410.    * @method _onTrigger
    411.    * @param {Number} x
    412.    * @param {Number} y
    413.    * @private
    414.    */
    415.   TouchInput._onTrigger = function(x, y) {
    416.     this._events.triggered = true;
    417.     this._x = x;
    418.     this._y = y;
    419.     this._date = Date.now();
    420.   };
    421.   /**
    422.    * @static
    423.    * @method _onCancel
    424.    * @param {Number} x
    425.    * @param {Number} y
    426.    * @private
    427.    */
    428.   TouchInput._onCancel = function(x, y) {
    429.     this._events.cancelled = true;
    430.     this._x = x;
    431.     this._y = y;
    432.   };
    433.   /**
    434.    * @static
    435.    * @method _onMove
    436.    * @param {Number} x
    437.    * @param {Number} y
    438.    * @private
    439.    */
    440.   TouchInput._onMove = function(x, y) {
    441.     this._events.moved = true;
    442.     this._x = x;
    443.     this._y = y;
    444.   };
    445.   /**
    446.    * @static
    447.    * @method _onRelease
    448.    * @param {Number} x
    449.    * @param {Number} y
    450.    * @private
    451.    */
    452.   TouchInput._onRelease = function(x, y) {
    453.     this._events.released = true;
    454.     this._x = x;
    455.     this._y = y;
    456.   };
    457.   Window_Selectable.prototype.processTouch = function() {
    458.     if (this.isOpenAndActive()) {
    459.       if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
    460.         //this._touching = true;
    461.       } else if ((TouchInput.judgeClicked("left")) && this.isTouchedInsideFrame()) {
    462.         this.onTouch(false);
    463.         this.onTouch(true);
    464.       } else if (TouchInput.judgeClicked("touch") && this.isTouchedInsideFrame()) {
    465.         this.onTouch(false);
    466.         this.onTouch(true);
    467.       } else if (TouchInput.isCancelled()) {
    468.         if (this.isCancelEnabled()) {
    469.           this.processCancel();
    470.         }
    471.       }
    472.       if (this._touching) {
    473.         if (TouchInput.isPressed()) {
    474.           this.onTouch(false);
    475.         } else {
    476.           this._touching = false;
    477.         }
    478.       }
    479.       if (TouchInput.isMoved() && this.isTouchedInsideContents()) {
    480.         this.onTouch(false);
    481.       }
    482.     } else {
    483.       this._touching = false;
    484.     }
    485.   };
    486.   Window_Selectable.prototype.onTouch = function(triggered) {
    487.     var lastIndex = this.index();
    488.     var x = this.canvasToLocalX(TouchInput.x);
    489.     var y = this.canvasToLocalY(TouchInput.y);
    490.     var hitIndex = this.hitTest(x, y);
    491.     if (hitIndex >= 0) {
    492.       if (hitIndex === this.index()) {
    493.         if (triggered && this.isTouchOkEnabled()) {
    494.           this.processOk();
    495.         }
    496.       } else if (this.isCursorMovable()) {
    497.         this.select(hitIndex);
    498.         if (triggered && this.isTouchOkEnabled()) {
    499.           this.processOk();
    500.         }
    501.       }
    502.     } else if (this._stayCount >= 10) {
    503.       if (y < this.padding) {
    504.         this.cursorUp();
    505.       } else if (y >= this.height - this.padding) {
    506.         this.cursorDown();
    507.       }
    508.     }
    509.     if (this.index() !== lastIndex && triggered) {
    510.       SoundManager.playCursor();
    511.     }
    512.   };
    513.   Window_Selectable.prototype.isTouchedInsideContents = function() {
    514.     var x = this.canvasToLocalX(TouchInput.x);
    515.     var y = this.canvasToLocalY(TouchInput.y);
    516.     if (Imported.TWDP_BaseWindowEx) {
    517.       return x >= this.paddingLeft() && y >= this.paddingTop() && x < this.width - this.paddingLeft() - this.paddingRight() && y < this.height - this.paddingTop() - this.paddingBottom();
    518.     } else {
    519.       return x >= this.padding && y >= this.padding && x < this.width - this.padding * 2 && y < this.height - this.padding * 2;
    520.     }
    521.   };
    522.   $.backup.Window_Selectable_processWheel = Window_Selectable.prototype.processWheel;
    523.   Window_Selectable.prototype.processWheel = function() {
    524.     $.backup.Window_Selectable_processWheel.call(this);
    525.     if (this._touchSrollY === undefined) {
    526.       this._touchSrollY = 0;
    527.     }
    528.     if (this.isOpenAndActive()) {
    529.       if (TouchInput.judgePressed('touch')) {
    530.         if (this._touchSrollY * TouchInput.touchScroll.y < 0) {
    531.           this._touchSrollY = 0;
    532.         }
    533.         this._touchSrollY += TouchInput.touchScroll.y;
    534.       } else {
    535.         this._touchSrollY = 0;
    536.       }
    537.       //console.log(this._touchSrollY, TouchInput.touchScroll.y, this._cursorRect.height);
    538.       if (this._touchSrollY >= this.itemHeight()) {
    539.         this.scrollDown();
    540.         this._touchSrollY -= this.itemHeight();
    541.       }
    542.       if (this._touchSrollY = 0 && y >= 0 && x < this.width && y < this.height;
    543.   };
    544.   Game_Player.prototype.triggerTouchActionD1 = function(x1, y1) {
    545.     if ($gameMap.airship().pos(x1, y1)) {
    546.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))  && this.getOnOffVehicle()) {
    547.         return true;
    548.       }
    549.     }
    550.     this.checkEventTriggerHere([0]);
    551.     return $gameMap.setupStartingEvent();
    552.   };
    553.   Game_Player.prototype.triggerTouchActionD2 = function(x2, y2) {
    554.     if ($gameMap.boat().pos(x2, y2) || $gameMap.ship().pos(x2, y2)) {
    555.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) && this.getOnVehicle()) {
    556.         return true;
    557.       }
    558.     }
    559.     if (this.isInBoat() || this.isInShip()) {
    560.       if ((TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch"))  && this.getOffVehicle()) {
    561.         return true;
    562.       }
    563.     }
    564.     this.checkEventTriggerThere([0, 1, 2]);
    565.     return $gameMap.setupStartingEvent();
    566.   };
    567.   Game_Player.prototype.triggerTouchActionD3 = function(x2, y2) {
    568.     if ($gameMap.isCounter(x2, y2)) {
    569.       this.checkEventTriggerThere([0, 1, 2]);
    570.     }
    571.     return $gameMap.setupStartingEvent();
    572.   };
    573.   // Scene_Map.prototype.isFastForward = function() {
    574.   //   return ($gameMap.isEventRunning() && !SceneManager.isSceneChanging() &&
    575.   //     (Input.isLongPressed('ok') || TouchInput.isLongPressed()));
    576.   // };
    577.   Scene_Map.prototype.processMapTouch = function() {
    578.     if (TouchInput.judgeLongPressed("left", 15) || TouchInput.judgeLongPressed("touch", 15) || TouchInput.judgeLongPressed("right", 15)) {
    579.       var x = $gameMap.canvasToMapX(TouchInput.x);
    580.       var y = $gameMap.canvasToMapY(TouchInput.y);
    581.       $gameTemp.setPressedDest(x, y);
    582.       $gameTemp.clearDestination();
    583.     } else if ($gameTemp.isPressedDestValid() && (!TouchInput.judgePressed("left") || !TouchInput.judgePressed("touch") || !TouchInput.judgePressed("right"))) {
    584.       $gameTemp.clearPressedDest();
    585.     } else if (TouchInput.judgeClicked("left") || TouchInput.judgeClicked("touch")) {
    586.       var x = $gameMap.canvasToMapX(TouchInput.x);
    587.       var y = $gameMap.canvasToMapY(TouchInput.y);
    588.       $gameTemp.setDestination(x, y);
    589.     }
    590.   };
    591.   Scene_Gameover.prototype.isTriggered = function() {
    592.     return Input.isTriggered('ok') || TouchInput.isTriggered();
    593.   };
    594.   Game_Player.prototype.moveByInput = function() {
    595.     if (!this.isMoving() && this.canMove()) {
    596.       var direction = this.getInputDirection();
    597.       if (direction > 0) {
    598.         $gameTemp.clearDestination();
    599.       } else if ($gameTemp.isDestinationValid()) {
    600.         var x = $gameTemp.destinationX();
    601.         var y = $gameTemp.destinationY();
    602.         direction = this.findDirectionTo(x, y);
    603.       } else if ($gameTemp.isPressedDestValid()) {
    604.         var x = $gameTemp._pressedDestX;
    605.         var y = $gameTemp._pressedDestY;
    606.         direction = this.findDirectionTo(x, y);
    607.       }
    608.       if (direction > 0) {
    609.         this.executeMove(direction);
    610.       }
    611.     }
    612.   };
    613.   Game_Temp.prototype.setPressedDest = function(x, y) {
    614.     this._pressedDestX = x;
    615.     this._pressedDestY = y;
    616.   }
    617.   Game_Temp.prototype.clearPressedDest = function() {
    618.     this._pressedDestX = null;
    619.     this._pressedDestY = null;
    620.   }
    621.   Game_Temp.prototype.isPressedDestValid = function() {
    622.     if (this._pressedDestX === null || this._pressedDestX === undefined) {
    623.       return false;
    624.     }
    625.     return true;
    626.   }
    627.   Game_Temp.prototype.isPressedDestFar = function() {
    628.     if (!this.isPressedDestValid()) {
    629.       return false;
    630.     }
    631.     if (distanceOfTwoPoints($gamePlayer.x, $gamePlayer.y, this._pressedDestX, this._pressedDestY) >= 3) {
    632.       return true;
    633.     }
    634.     return false;
    635.   }
    636.   Game_Player.prototype.findPressedDestDirection = function(x, y) {
    637.     if (this.x === x && this.y === y) {
    638.       return 0;
    639.     }
    640.     var deltaX = this.x - x;
    641.     var deltaY = this.y - y;
    642.     if (Math.abs(deltaX) > Math.abs(deltaY)) {
    643.       if (deltaX > 0) {
    644.         return 4;
    645.       } else {
    646.         return 6;
    647.       }
    648.     } else {
    649.       if (deltaY > 0) {
    650.         return 8;
    651.       } else {
    652.         return 2;
    653.       }
    654.     }
    655.   }
    656.   Game_Player.prototype.updateDashing = function() {
    657.     if (this.isMoving()) {
    658.       return;
    659.     }
    660.     if (this.canMove() && !this.isInVehicle() && !$gameMap.isDashDisabled()) {
    661.       this._dashing = this.isDashButtonPressed() || $gameTemp.isDestinationValid() || $gameTemp.isPressedDestFar();
    662.     } else {
    663.       this._dashing = false;
    664.     }
    665.   };
    666.   if (Imported.YEP_BattleEngineCore) {
    667.     Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
    668.       if (!enemy) return false;
    669.       if (!enemy.isSpriteVisible()) return false;
    670.       var x = TouchInput.x;
    671.       var y = TouchInput.y;
    672.       var rect = new Rectangle();
    673.       rect.width = enemy.spriteWidth();
    674.       rect.height = enemy.spriteHeight();
    675.       rect.x = enemy.spritePosX() - rect.width / 2;
    676.       rect.y = enemy.spritePosY() - rect.height;
    677.       return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
    678.         y < rect.y + rect.height);
    679.     };
    680.   }
    681.   // Yanfly.BEC.Window_BattleActor_processTouch =
    682.   //   Window_BattleActor.prototype.processTouch;
    683.   // Window_BattleActor.prototype.processTouch = function() {
    684.   //   if (eval(Yanfly.Param.BECActorSelect) && this.isOpenAndActive()) {
    685.   //     if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
    686.   //       if (this.getClickedActor() >= 0) {
    687.   //         var index = this.getClickedActor();
    688.   //         if (this.index() === index) {
    689.   //           return this.processOk();
    690.   //         } else {
    691.   //           SoundManager.playCursor();
    692.   //           return this.select(index);
    693.   //         }
    694.   //       }
    695.   //     }
    696.   //     if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
    697.   //       if (this.getClickedActor() >= 0) {
    698.   //         var index = this.getClickedActor();
    699.   //         if (this.index() !== index) {
    700.   //           SoundManager.playCursor();
    701.   //           return this.select(index);
    702.   //         }
    703.   //       }
    704.   //     }
    705.   //     if (Yanfly.Param.BECSelectMouseOver) {
    706.   //       var index = this.getMouseOverActor();
    707.   //       if (index >= 0 && this.index() !== index) {
    708.   //         SoundManager.playCursor();
    709.   //         return this.select(index);
    710.   //       }
    711.   //     }
    712.   //   }
    713.   //   Yanfly.BEC.Window_BattleActor_processTouch.call(this);
    714.   // };
    715.   //
    716.   // Window_BattleActor.prototype.isClickedActor = function(actor) {
    717.   //   if (!actor) return false;
    718.   //   if (!actor.isSpriteVisible()) return false;
    719.   //   if (!actor.isAppeared()) return false;
    720.   //   var x = TouchInput.x;
    721.   //   var y = TouchInput.y;
    722.   //   var rect = new Rectangle();
    723.   //   rect.width = actor.spriteWidth();
    724.   //   rect.height = actor.spriteHeight();
    725.   //   rect.x = actor.spritePosX() - rect.width / 2;
    726.   //   rect.y = actor.spritePosY() - rect.height;
    727.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
    728.   //     y < rect.y + rect.height);
    729.   // };
    730.   //
    731.   // Window_BattleActor.prototype.isMouseOverActor = function(actor) {
    732.   //   if (!actor) return false;
    733.   //   if (!actor.isSpriteVisible()) return false;
    734.   //   if (!actor.isAppeared()) return false;
    735.   //   var x = TouchInput._mouseOverX;
    736.   //   var y = TouchInput._mouseOverY;
    737.   //   var rect = new Rectangle();
    738.   //   rect.width = actor.spriteWidth();
    739.   //   rect.height = actor.spriteHeight();
    740.   //   rect.x = actor.spritePosX() - rect.width / 2;
    741.   //   rect.y = actor.spritePosY() - rect.height;
    742.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
    743.   //     y < rect.y + rect.height);
    744.   // };
    745.   //
    746.   // Yanfly.BEC.Window_BattleEnemy_processTouch =
    747.   //   Window_BattleEnemy.prototype.processTouch;
    748.   // Window_BattleEnemy.prototype.processTouch = function() {
    749.   //   if (eval(Yanfly.Param.BECEnemySelect) && this.isOpenAndActive()) {
    750.   //     if (TouchInput.isTriggered() && !this.isTouchedInsideFrame()) {
    751.   //       if (this.getClickedEnemy() >= 0) {
    752.   //         var index = this.getClickedEnemy();
    753.   //         if (this.index() === index) {
    754.   //           return this.processOk();
    755.   //         } else {
    756.   //           SoundManager.playCursor();
    757.   //           return this.select(index);
    758.   //         }
    759.   //       }
    760.   //     }
    761.   //     if (TouchInput.isPressed() && !this.isTouchedInsideFrame()) {
    762.   //       if (this.getClickedEnemy() >= 0) {
    763.   //         var index = this.getClickedEnemy();
    764.   //         if (this.index() !== index) {
    765.   //           SoundManager.playCursor();
    766.   //           return this.select(index);
    767.   //         }
    768.   //       }
    769.   //     }
    770.   //     if (Yanfly.Param.BECSelectMouseOver) {
    771.   //       var index = this.getMouseOverEnemy();
    772.   //       if (index >= 0 && this.index() !== index) {
    773.   //         SoundManager.playCursor();
    774.   //         return this.select(index);
    775.   //       }
    776.   //     }
    777.   //   };
    778.   //   Yanfly.BEC.Window_BattleEnemy_processTouch.call(this);
    779.   // };
    780.   //
    781.   // Window_BattleEnemy.prototype.isClickedEnemy = function(enemy) {
    782.   //   if (!enemy) return false;
    783.   //   if (!enemy.isSpriteVisible()) return false;
    784.   //   var x = TouchInput.x;
    785.   //   var y = TouchInput.y;
    786.   //   var rect = new Rectangle();
    787.   //   rect.width = enemy.spriteWidth();
    788.   //   rect.height = enemy.spriteHeight();
    789.   //   rect.x = enemy.spritePosX() - rect.width / 2;
    790.   //   rect.y = enemy.spritePosY() - rect.height;
    791.   //   return (x >= rect.x && y >= rect.y && x < rect.x + rect.width &&
    792.   //     y < rect.y + rect.height);
    793.   // };
    794.   //
    795.   // Window_BattleEnemy.prototype.getMouseOverEnemy = function() {
    796.   //   for (var i = 0; i < this._enemies.length; ++i) {
    797.   //     var enemy = this._enemies[i];
    798.   //     if (!enemy) continue;
    799.   //     if (this.isClickedEnemy(enemy)) {
    800.   //       if (this._selectDead && !enemy.isDead()) continue;
    801.   //       var index = this._enemies.indexOf(enemy)
    802.   //       if (this._inputLock && index !== this.index()) continue;
    803.   //       return index;
    804.   //     }
    805.   //   }
    806.   //   return -1;
    807.   // };
    808. })(TWDP.TEE);
    复制代码
      
                 本帖来自P1论坛作者trentswd,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=388144  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2025-3-10 12:04 , Processed in 0.110372 second(s), 53 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表