在Starling中禁用鼠标拦截器

时间:2013-04-24 19:17:54

标签: actionscript-3 input touch starling-framework

如何阻止所有鼠标触控输入到我的Actionscript 3 Starling游戏中?

基本上我需要在一段时间内忽略所有触摸事件。

2 个答案:

答案 0 :(得分:3)

如果您不希望对象可触摸,则可以禁用“可触摸”属性。当它被禁用时,对象及其子节点都不会再接收任何触摸事件。

无需添加新的显示对象以防止触摸。

this.touchable = false;

答案 1 :(得分:1)

开发出快速解决方案!基本上创建一个与屏幕大小相同的Quad,并将其添加到最前面的图层。

添加到最前层文件的init()函数:

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

然后定义这些功能:

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;
    }
}

调用此功能激活Touch Toucher:

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