[JS] Disable Sprite Button/ClickHandlers temporarily?

megumi014

Veteran
Veteran
Joined
Mar 8, 2017
Messages
130
Reaction score
212
First Language
Spanish
Primarily Uses
RMMV
Hiya!

As the title says: is there any way to disable a sprite button temporarily? (And activate it later?) Like with this._randomWindow.deactivate(); but for the mouse input?

I'm trying to set up a couple of windows on the Title Screen, and I could disable the mouse alltogether but I'd rather not.

I found this piece of code so I gueeess it's possible but I just can't find the necessary word. I tried with invisible but it didn't exist xD

Code:
Sprite_Button.prototype.processTouch = function() {
    if (this.isActive()) {
        if (TouchInput.isTriggered() && this.isButtonTouched()) {
            this._touching = true;
        }
        if (this._touching) {
            if (TouchInput.isReleased() || !this.isButtonTouched()) {
                this._touching = false;
                if (TouchInput.isReleased()) {
                    this.callClickHandler();
                }
            }
        }
    } else {
        this._touching = false;
    }
};

Sprite_Button.prototype.isActive = function() {
    var node = this;
    while (node) {
        if (!node.visible) {
            return false;
        }
        node = node.parent;
    }
    return true;
};
 

Trace

A Rieri Fan :3
Member
Joined
Jun 7, 2014
Messages
10
Reaction score
9
First Language
Indonesia
Primarily Uses
RMMV
Hey, you can create another this.isActive() function but for that specific function

Code:
Sprite_Button.prototype.processTouch = function() {
    if (this.isActive() && this.isTouchActive()) { /////add this//////
        if (TouchInput.isTriggered() && this.isButtonTouched()) {
            this._touching = true;
        }
        if (this._touching) {
            if (TouchInput.isReleased() || !this.isButtonTouched()) {
                this._touching = false;
                if (TouchInput.isReleased()) {
                    this.callClickHandler();
                }
            }
        }
    } else {
        this._touching = false;
    }
};

//don't need to edit this
Sprite_Button.prototype.isActive = function() {
    var node = this;
    while (node) {
        if (!node.visible) {
            return false;
        }
        node = node.parent;
    }
    return true;
};

//new function
Sprite_Button.prototype.isTouchActive = function() {
    return this._touchActive;
};

//new activate and deactivate function for touch
Sprite_Button.prototype.activateTouch = function() {
    this._touchActive = true;
};

Sprite_Button.prototype.deactivateTouch = function() {
    this._touchActive = false;
};
so whenever you call this.deactivateTouch, you'll disable the processTouch temporarily

Hope this helps...
:kaohi:
 

megumi014

Veteran
Veteran
Joined
Mar 8, 2017
Messages
130
Reaction score
212
First Language
Spanish
Primarily Uses
RMMV
Thank you! That makes so much sense :D I made a conditional check on the title screen that worked around the problem, but it's way more efficient to modify the Sprite Button function itself :kaoswt: Thanks again!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Small rant: While using SRD Hud maker for a battle hud, I typed in the wrong script call and got an error, but then forgot to delete the piece that caused the error before closed the Hud maker and hit F5 to restart the game. Now everytime I engage in a battle my game crashes...
:kaolivid:
Would Jump into Javascript be best off continuing to break down the MV core files, or would people prefer a quick detour to cover everything that's changed in the core from MV to MZ?
Not going to lie... PIXI Particles make fantastic graphics... But predicting the hitbox of something with a "fixed size" but whose graphics can stick out past that, is quite challenging. :kaoswt:
Would you like a glass of spiders?

Forum statistics

Threads
100,530
Messages
976,897
Members
132,081
Latest member
Kaezyelnatz
Top