查看: 1540|回复: 2

[有事请教] 透明像素点击无效的图片按钮脚本?

[复制链接]
梦石
0
星屑
10510
在线时间
1118 小时
注册时间
2015-2-10
回帖
164
发表于 2023-11-2 15:53:58 | 显示全部楼层 |阅读模式
悬赏50星屑已解决
本帖最后由 fbeds 于 2023-11-2 22:46 编辑

我使用了图片按钮脚本,但是发现显示的图片点击了透明像素的地方依然会生效。我想改成如果玩家点击了图片按钮的透明位置,会判定成没有点中,只有点击了其非透明部分才会执行后续事件,该怎么弄?

  1. //=============================================================================
  2. // RPG Maker MZ - Button Picture
  3. //=============================================================================

  4. /*:
  5. * @target MZ
  6. * @plugindesc Makes a picture clickable.
  7. * @author Yoji Ojima
  8. *
  9. * @help ButtonPicture.js
  10. *
  11. * This plugin provides a command to call a common event when a picture is
  12. * clicked.
  13. *
  14. * Use it in the following procedure.
  15. *   1. Execute "Show Picture" to display your button image.
  16. *   2. Call the plugin command "Set Button Picture".
  17. *
  18. * @command set
  19. * @text Set Button Picture
  20. * @desc Makes the specified picture clickable.
  21. *
  22. * @arg pictureId
  23. * @type number
  24. * @min 1
  25. * @max 100
  26. * @default 1
  27. * @text Picture Number
  28. * @desc Control number of the picture.
  29. *
  30. * @arg commonEventId
  31. * @type common_event
  32. * @default 1
  33. * @text Common Event
  34. * @desc Common event to call when the picture is clicked.
  35. */

  36. /*:ja
  37. * @target MZ
  38. * @plugindesc ピクチャをクリック可能にします。
  39. * @author Yoji Ojima
  40. *
  41. * @help ButtonPicture.js
  42. *
  43. * このプラグインは、ピクチャのクリック時にコモンイベントを呼び出すコマンドを
  44. * 提供します。
  45. *
  46. * 次の手順で使用してください。
  47. *   1. 「ピクチャの表示」を実行して、ボタン画像を表示します。
  48. *   2. プラグインコマンド「ボタンピクチャの設定」を呼び出します。
  49. *
  50. * @command set
  51. * @text ボタンピクチャの設定
  52. * @desc 指定したピクチャをクリック可能にします。
  53. *
  54. * @arg pictureId
  55. * @type number
  56. * @min 1
  57. * @max 100
  58. * @default 1
  59. * @text ピクチャ番号
  60. * @desc ピクチャの管理番号です。
  61. *
  62. * @arg commonEventId
  63. * @type common_event
  64. * @default 1
  65. * @text コモンイベント
  66. * @desc ピクチャがクリックされた時に呼び出すコモンイベントです。
  67. */

  68. (() => {
  69.     const pluginName = "ButtonPicture";

  70.     PluginManager.registerCommand(pluginName, "set", args => {
  71.         const pictureId = Number(args.pictureId);
  72.         const commonEventId = Number(args.commonEventId);
  73.         const picture = $gameScreen.picture(pictureId);
  74.         if (picture) {
  75.             picture.mzkp_commonEventId = commonEventId;
  76.         }
  77.     });

  78.     Sprite_Picture.prototype.isClickEnabled = function() {
  79.         const picture = this.picture();
  80.         return picture && picture.mzkp_commonEventId && !$gameMessage.isBusy();
  81.     };

  82.     Sprite_Picture.prototype.onClick = function() {
  83.         $gameTemp.reserveCommonEvent(this.picture().mzkp_commonEventId);
  84.     };

  85.     Spriteset_Base.prototype.mzkp_isAnyPicturePressed = function() {
  86.         return this._pictureContainer.children.some(sprite =>
  87.             sprite.isPressed()
  88.         );
  89.     };

  90.     const _Scene_Map_isAnyButtonPressed =
  91.         Scene_Map.prototype.isAnyButtonPressed;
  92.     Scene_Map.prototype.isAnyButtonPressed = function() {
  93.         return (
  94.             _Scene_Map_isAnyButtonPressed.apply(this, arguments) ||
  95.             this._spriteset.mzkp_isAnyPicturePressed()
  96.         );
  97.     };
  98. })();
复制代码

最佳答案

查看完整内容

PictureCallCommon https://raw.githubusercontent.com/triacontane/RPGMakerMV/mz_master/PictureCallCommon.js Ignis Touch Pictures https://raizen884.itch.io/ignis-touch-pictures Picture Common Events https://visustellamz.itch.io/picture-common-events
梦石
0
星屑
3244
在线时间
566 小时
注册时间
2020-8-20
回帖
71
发表于 2023-11-2 15:53:59 | 显示全部楼层
回复

使用道具 举报

梦石
2
星屑
8479
在线时间
463 小时
注册时间
2021-12-4
回帖
486

MZ评测员

发表于 2023-11-3 09:58:26 | 显示全部楼层
如果按钮的形状比较规则(比如说椭圆形),可以使用解析几何的方法把坐标满足的不等式组找到……(啊?)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部