查看: 1447|回复: 2

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

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

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

[pre lang="ruby"]//=============================================================================
// RPG Maker MZ - Button Picture
//=============================================================================

/*:
* @target MZ
* @plugindesc Makes a picture clickable.
* @author Yoji Ojima
*
* @help ButtonPicture.js
*
* This plugin provides a command to call a common event when a picture is
* clicked.
*
* Use it in the following procedure.
*   1. Execute "Show Picture" to display your button image.
*   2. Call the plugin command "Set Button Picture".
*
* @command set
* @text Set Button Picture
* @desc Makes the specified picture clickable.
*
* @arg pictureId
* @type number
* @min 1
* @max 100
* @default 1
* @text Picture Number
* @desc Control number of the picture.
*
* @arg commonEventId
* @type common_event
* @default 1
* @text Common Event
* @desc Common event to call when the picture is clicked.
*/

/*:ja
* @target MZ
* @plugindesc ピクチャをクリック可能にします。
* @author Yoji Ojima
*
* @help ButtonPicture.js
*
* このプラグインは、ピクチャのクリック時にコモンイベントを呼び出すコマンドを
* 提供します。
*
* 次の手順で使用してください。
*   1. 「ピクチャの表示」を実行して、ボタン画像を表示します。
*   2. プラグインコマンド「ボタンピクチャの設定」を呼び出します。
*
* @command set
* @text ボタンピクチャの設定
* @desc 指定したピクチャをクリック可能にします。
*
* @arg pictureId
* @type number
* @min 1
* @max 100
* @default 1
* @text ピクチャ番号
* @desc ピクチャの管理番号です。
*
* @arg commonEventId
* @type common_event
* @default 1
* @text コモンイベント
* @desc ピクチャがクリックされた時に呼び出すコモンイベントです。
*/

(() => {
    const pluginName = "ButtonPicture";

    PluginManager.registerCommand(pluginName, "set", args => {
        const pictureId = Number(args.pictureId);
        const commonEventId = Number(args.commonEventId);
        const picture = $gameScreen.picture(pictureId);
        if (picture) {
            picture.mzkp_commonEventId = commonEventId;
        }
    });

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

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

    Spriteset_Base.prototype.mzkp_isAnyPicturePressed = function() {
        return this._pictureContainer.children.some(sprite =>
            sprite.isPressed()
        );
    };

    const _Scene_Map_isAnyButtonPressed =
        Scene_Map.prototype.isAnyButtonPressed;
    Scene_Map.prototype.isAnyButtonPressed = function() {
        return (
            _Scene_Map_isAnyButtonPressed.apply(this, arguments) ||
            this._spriteset.mzkp_isAnyPicturePressed()
        );
    };
})();
[/pre]

最佳答案

查看完整内容

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
星屑
3234
在线时间
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.

在本版发帖返回顶部