MZ ButtonPicture Triggered for Opaque Pixels Only?

Hello! I'm trying to use the ButtonPicture for a non-rectangular shape (as seen below), but even when I click on the transparent pixels, it still registers as a click and triggers the common event. Is there any way to just have the clicks only be registered when it is on an opaque pixel?

Thank you in advance!

1_PotatoSalad.png


This is what the hitbox would look like it I tried cropping the image to the edges; there's still a noticeable wedge sticking out that can be clicked ._.
1776435733748.png
You could try saving this as a .js file and loading it as a plugin:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Opacity threshold for clickable picture hit test.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/posts/1553909/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (() => {
"use strict";
  /** To be clickable, a pixel must have at least this much opacity (0~255). */
  const THRESHOLD = 1;

  /**
   * Determines scope:
   * - `true`: apply opacity check only for pictures.
   * - `false`: apply opacity check for all clickable sprites (e.g. enemies in battle).
   */
  const PICTURES_ONLY = true;

  /** Base class to modify. */
  const C = PICTURES_ONLY ? Sprite_Picture : Sprite_Clickable;

  // Patch - add opacity threshold to picture sprite hit test.
  const alias = C.prototype.hitTest;
  C.prototype.hitTest = function(x, y) {
    if (alias.apply(this, arguments)) {
      const b = this.bitmap;
      if (b) {
        const ax = this.anchor.x * this.width;
        const ay = this.anchor.y * this.height;
        const op = this.opacity / 255;
        return b.getAlphaPixel(x + ax, y + ay) * op >= THRESHOLD;
      }
      return true;
    }
    return false;
  };

})();
I haven't tested this, but it's a refactor of what I've used in my own plugin (Cae_PictureTouch), so it should work unless I've made a typo or something. 👋
You could try saving this as a .js file and loading it as a plugin:
Spoiler: plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Opacity threshold for clickable picture hit test.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/posts/1553909/
 * @help Free to use and/or modify for any project, no credit required.
 */
;void (() => {
"use strict";
  /** To be clickable, a pixel must have at least this much opacity (0~255). */
  const THRESHOLD = 1;

  /**
   * Determines scope:
   * - `true`: apply opacity check only for pictures.
   * - `false`: apply opacity check for all clickable sprites (e.g. enemies in battle).
   */
  const PICTURES_ONLY = true;

  /** Base class to modify. */
  const C = PICTURES_ONLY ? Sprite_Picture : Sprite_Clickable;

  // Patch - add opacity threshold to picture sprite hit test.
  const alias = C.prototype.hitTest;
  C.prototype.hitTest = function(x, y) {
    if (alias.apply(this, arguments)) {
      const b = this.bitmap;
      if (b) {
        const ax = this.anchor.x * this.width;
        const ay = this.anchor.y * this.height;
        const op = this.opacity / 255;
        return b.getAlphaPixel(x + ax, y + ay) * op >= THRESHOLD;
      }
      return true;
    }
    return false;
  };

})();
I haven't tested this, but it's a refactor of what I've used in my own plugin (Cae_PictureTouch), so it should work unless I've made a typo or something. 👋
OMG that picturetouch plugin is exactly what I needed!!! Thank you so much! 😀

Original thread: https://forums.rpgmakerweb.com/threads/buttonpicture-triggered-for-opaque-pixels-only.183295/