Gabe Karkanis
Gabe Karkanis

Reputation: 735

Disable Mouse Blocker in Starling

How to block all mouse touch input into my Actionscript 3 Starling game?

Basically I need to ignore all touch events for a set period of time.

Upvotes: 1

Views: 836

Answers (2)

SeOd
SeOd

Reputation: 61

If you don't want an object to be touchable, you can disable the "touchable" property. When it's disabled, neither the object nor its children will receive any more touch events.

There is no need to add new display object to prevent touches.

this.touchable = false;

Upvotes: 3

Gabe Karkanis
Gabe Karkanis

Reputation: 735

Developed a quick solution! Basically create a Quad that is the size of your screen, and add it to the front most layer.

Add to init() function of front most layer file:

Starling.current.addEventListener('TOUCH_BLOCKER_ENABLE', touchBlockerEnable);
Starling.current.addEventListener('TOUCH_BLOCKER_DISABLE', touchBlockerDisable);

Then define these functions:

private function touchBlockerEnable(e:Event):void
{
    if(!_quad)
    {
        _quad = new Quad(Starling.current.stage.width,Starling.current.stage.height,0xFFE6E6);
        _quad.x = 0;
        _quad.y = 0;
        _quad.alpha = 0.1;
        addChild(_quad);
    }
}

private function touchBlockerDisable(e:Event):void
{
    if(_quad)
    {
        removeChild(_quad);
        _quad = null;
    }
}

Call this function to activate the Touch Blocker:

Starling.current.dispatchEvent(new Event('TOUCH_BLOCKER_ENABLE'));

Upvotes: 1

Related Questions