[RMMZ] ゲーム内の明るさ調整は可能ですか?

皆さん、こんにちは。2026年になっても、すべてのモニターが同じように作られているわけではないことに改めて気づかされます。モニターの設定を変えずにゲーム内の明るさを調整するスライダーをゲーム内に実装するには、どうすればよいのでしょうか?この質問をしたのは、一部のゲームでは特定の照明レベルを想定して開発されている可能性があり、適切な設定があれば特にホラーゲームやステルスゲームにおいて素晴らしい体験になるからです。

あるいは、Tint Screenを使ってイベントを一つ作成することもできます。また、明るさを制御できるプラグインもあります。

@Son_ofHiroさんのアイデアに追加して、Tint Screenの落とし穴は、マップが夜や洞窟の tint に同じ設定を使用することです。そのため、それに基づく明るさオプションは、これらのイベントのいずれかが実行されるたびに上書きされてしまいます。

私は、画面 tint とは別に、明るさをオプションメニュー独自の項目として作成するのが良いと思います。以下は、50%から150%までの明るさ設定を追加し、音量設定とともに保存する小さなプラグインです:

/*:
 * @target MZ
 * @plugindesc オプションメニューに明るさのオプションを追加します。
 */

(() => {
    const MIN = 50;
    const MAX = 150;
    const STEP = 10;

    ConfigManager.brightness = 100;

    const _makeData = ConfigManager.makeData;
    ConfigManager.makeData = function() {
        const config = _makeData.call(this);
        config.brightness = this.brightness;
        return config;
    };

    const _applyData = ConfigManager.applyData;
    ConfigManager.applyData = function(config) {
        _applyData.call(this, config);
        this.brightness = "brightness" in config
            ? Number(config.brightness).clamp(MIN, MAX)
            : 100;
    };

    const _addGeneralOptions = Window_Options.prototype.addGeneralOptions;
    Window_Options.prototype.addGeneralOptions = function() {
        _addGeneralOptions.call(this);
        this.addCommand("Brightness", "brightness");
    };

    const _statusText = Window_Options.prototype.statusText;
    Window_Options.prototype.statusText = function(index) {
        if (this.commandSymbol(index) === "brightness") {
            return ConfigManager.brightness + "%";
        }
        return _statusText.call(this, index);
    };

    Window_Options.prototype.changeBrightness = function(forward, wrap) {
        let value = ConfigManager.brightness + (forward ? STEP : -STEP);
        if (value > MAX && wrap) {
            value = MIN;
        }
        this.changeValue("brightness", value.clamp(MIN, MAX));
    };

    const _processOk = Window_Options.prototype.processOk;
    Window_Options.prototype.processOk = function() {
        if (this.currentSymbol() === "brightness") {
            this.changeBrightness(true, true);
        } else {
            _processOk.call(this);
        }
    };

    const _cursorRight = Window_Options.prototype.cursorRight;
    Window_Options.prototype.cursorRight = function() {
        if (this.currentSymbol() === "brightness") {
            this.changeBrightness(true, false);
        } else {
            _cursorRight.call(this);
        }
    };

    const _cursorLeft = Window_Options.prototype.cursorLeft;
    Window_Options.prototype.cursorLeft = function() {
        if (this.currentSymbol() === "brightness") {
            this.changeBrightness(false, false);
        } else {
            _cursorLeft.call(this);
        }
    };

    const _maxCommands = Scene_Options.prototype.maxCommands;
    Scene_Options.prototype.maxCommands = function() {
        return _maxCommands.call(this) + 1;
    };

    const _createColorFilter = Scene_Base.prototype.createColorFilter;
    Scene_Base.prototype.createColorFilter = function() {
        _createColorFilter.call(this);
        this._brightnessFilter = new PIXI.filters.ColorMatrixFilter();
        this.filters = this.filters.concat(this._brightnessFilter);
    };

    const _updateColorFilter = Scene_Base.prototype.updateColorFilter;
    Scene_Base.prototype.updateColorFilter = function() {
        _updateColorFilter.call(this);
        this._brightnessFilter.brightness(ConfigManager.brightness / 100, false);
    };
})();

これをプロジェクトの js/plugins フォルダに Brightness.js という名前で保存し、プラグインマネージャーで有効にしてください。VisuStella の Options Core のように、すでにオプションメニューを再構築しているプラグインを使用している場合は、そこに表示されるかどうかはわかりません。

本当にうまくいきました!ありがとうございます!:purple_heart: