[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 Posts

Latest Profile Posts

When you discover great tileset resources that you completely forgot that you had. :kaomad3::kaopride:
Just got a better look at the MZ RTP. I'm very happy with it, especially the sci-fi tiles and sprites. Glad I pre-ordered.
I've just checked the VisuStella Plugins for MZ and there are already 11 plugins. The Yanfly team(perhaps a big one?) really works so effectively and efficiently that some MZ users can likely use tons of Yanfly plugins right after MZ's released (still 13 days from now). I wonder if any other plugin developer(or team) will try to compete with Yanfly this time, no matter how slim the chance to win is :)
Hello! :kaopride:I am new to RPG Maker, though I have been lurking the forums for a while. :kaoswt: Hope to make some friends and learn some stuff here! :kaothx:
And now since I've got the whole game parts working, the *contents* await.

Forum statistics

Threads
100,594
Messages
977,582
Members
132,194
Latest member
linkvaovn88com
Top