#Clickable-when-hidden

10 messages · Page 1 of 1 (latest)

peak sail
#

Hidden game object (alpha is 0 and/or invisible) will be ignored during input detecting process.
Here is a hack solution to create a game object class which is clickable when hidden

var ClickableWhenHidden = function (GOClass) {
    var WillRender = GOClass.prototype.willRender;
    return class Base extends GOClass {
        // Override default behavior, always return true even if this game object is invisible.
        willRender(camera) {
            return true;
        }

        renderWebGL(renderer, src, camera, parentMatrix) {
            // Don't render if Default willRender method return false
            if (!WillRender.call(this, camera)) {
                return;
            }
            super.renderWebGL(renderer, src, camera, parentMatrix);
        }

        renderCanvas(renderer, src, camera, parentMatrix) {
            // Don't render if Default willRender method return false
            if (!WillRender.call(this, camera)) {
                return;
            }
            super.renderCanvas(renderer, src, camera, parentMatrix);
        }
    }
}

Demo : https://phaser.io/sandbox/RmZYwcar

#

A normal/better solution is to add a render-able game object into a container, then attach touch events on that parent container, therefore, this render-able game object could be hidden, and parent container can still receive touch events.

tall crescent
#

I usually just use .001 alpha

#

¯_(ツ)_/¯

lucid vine
tall crescent
#

no idea, it's just a hack to make phaser still consider it visible for input

lucid vine
#

Nah, I mean, I've done some experimenting but is there a lower limit on what can be tweened, like .00001 etc...if thats what you were saying you didn't know, no sweat.

tall crescent
#

I expect the only limit is from the inherent precision issues of floating point numbers in that case

lucid vine
#

So that's what, like 8 digits?

#

.0000001 or seven, I guess. I'll google.