设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 396|回复: 2
打印 上一主题 下一主题

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

[复制链接]

Lv4.逐梦者

梦石
0
星屑
7028
在线时间
878 小时
注册时间
2015-2-10
帖子
248
跳转到指定楼层
1
发表于 2023-11-2 15:53:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
50星屑
本帖最后由 fbeds 于 2023-11-2 22:46 编辑

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

RUBY 代码复制
  1. //=============================================================================
  2. // RPG Maker MZ - Button Picture
  3. //=============================================================================
  4.  
  5. /*:
  6. * @target MZ
  7. * @plugindesc Makes a picture clickable.
  8. * @author Yoji Ojima
  9. *
  10. * @help ButtonPicture.js
  11. *
  12. * This plugin provides a command to call a common event when a picture is
  13. * clicked.
  14. *
  15. * Use it in the following procedure.
  16. *   1. Execute "Show Picture" to display your button image.
  17. *   2. Call the plugin command "Set Button Picture".
  18. *
  19. * @command set
  20. * @text Set Button Picture
  21. * @desc Makes the specified picture clickable.
  22. *
  23. * @arg pictureId
  24. * @type number
  25. * @min 1
  26. * @max 100
  27. * @default 1
  28. * @text Picture Number
  29. * @desc Control number of the picture.
  30. *
  31. * @arg commonEventId
  32. * @type common_event
  33. * @default 1
  34. * @text Common Event
  35. * @desc Common event to call when the picture is clicked.
  36. */
  37.  
  38. /*:ja
  39. * @target MZ
  40. * @plugindesc ピクチャをクリック可能にします。
  41. * @author Yoji Ojima
  42. *
  43. * @help ButtonPicture.js
  44. *
  45. * このプラグインは、ピクチャのクリック時にコモンイベントを呼び出すコマンドを
  46. * 提供します。
  47. *
  48. * 次の手順で使用してください。
  49. *   1. 「ピクチャの表示」を実行して、ボタン画像を表示します。
  50. *   2. プラグインコマンド「ボタンピクチャの設定」を呼び出します。
  51. *
  52. * @command set
  53. * @text ボタンピクチャの設定
  54. * @desc 指定したピクチャをクリック可能にします。
  55. *
  56. * @arg pictureId
  57. * @type number
  58. * @min 1
  59. * @max 100
  60. * @default 1
  61. * @text ピクチャ番号
  62. * @desc ピクチャの管理番号です。
  63. *
  64. * @arg commonEventId
  65. * @type common_event
  66. * @default 1
  67. * @text コモンイベント
  68. * @desc ピクチャがクリックされた時に呼び出すコモンイベントです。
  69. */
  70.  
  71. (() => {
  72.     const pluginName = "ButtonPicture";
  73.  
  74.     PluginManager.registerCommand(pluginName, "set", args => {
  75.         const pictureId = Number(args.pictureId);
  76.         const commonEventId = Number(args.commonEventId);
  77.         const picture = $gameScreen.picture(pictureId);
  78.         if (picture) {
  79.             picture.mzkp_commonEventId = commonEventId;
  80.         }
  81.     });
  82.  
  83.     Sprite_Picture.prototype.isClickEnabled = function() {
  84.         const picture = this.picture();
  85.         return picture && picture.mzkp_commonEventId && !$gameMessage.isBusy();
  86.     };
  87.  
  88.     Sprite_Picture.prototype.onClick = function() {
  89.         $gameTemp.reserveCommonEvent(this.picture().mzkp_commonEventId);
  90.     };
  91.  
  92.     Spriteset_Base.prototype.mzkp_isAnyPicturePressed = function() {
  93.         return this._pictureContainer.children.some(sprite =>
  94.             sprite.isPressed()
  95.         );
  96.     };
  97.  
  98.     const _Scene_Map_isAnyButtonPressed =
  99.         Scene_Map.prototype.isAnyButtonPressed;
  100.     Scene_Map.prototype.isAnyButtonPressed = function() {
  101.         return (
  102.             _Scene_Map_isAnyButtonPressed.apply(this, arguments) ||
  103.             this._spriteset.mzkp_isAnyPicturePressed()
  104.         );
  105.     };
  106. })();

最佳答案

查看完整内容

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

Lv3.寻梦者

梦石
0
星屑
1980
在线时间
299 小时
注册时间
2020-8-20
帖子
58
2
发表于 2023-11-2 15:53:59 | 只看该作者
回复

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
5419
在线时间
388 小时
注册时间
2021-12-4
帖子
412
3
发表于 2023-11-3 09:58:26 | 只看该作者
如果按钮的形状比较规则(比如说椭圆形),可以使用解析几何的方法把坐标满足的不等式组找到……(啊?)
回复

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-28 18:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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