【问题标题】:Touch on device not working, while working on browser [cocos2d-JS]在浏览器上工作时触摸设备不工作[cocos2d-JS]
【发布时间】:2014-08-29 01:38:50
【问题描述】:

我用cocos2d-js做游戏,在浏览器上试了一下,运行良好,所有的触控功能都可以,但是当我编译到android设备时,触控功能根本不工作。

我通过以下方式注册触摸:

        cc.eventManager.addListener({
        event: cc.EventListener.TOUCH_ONE_BY_ONE,
        setTouchEnabled: true,
        setSwallowTouches: true,
        onTouchBegan: this.onTouchBegan,
    }, this)

并通过以下方式实现它:

onTouchBegan:function(touch, event){
    var pos = touch.getLocation();
    var touch_x = pos.x;
    var touch_y = pos.y;
...
}

【问题讨论】:

    标签: android cocos2d-x cocos2d-js


    【解决方案1】:

    我是这样实现的,它在WEB、Android和iOS上都能正常工作:

    if( 'touches' in cc.sys.capabilities ) { 
        this._touchListener = cc.EventListener.create({
            event: cc.EventListener.TOUCH_ALL_AT_ONCE,
            onTouchesBegan: function(touches, event) {
    
            },
    
            onTouchesMoved: function(touches, event) {
    
            },
    
            onTouchesEnded: function(touches, event) {
    
            }
        });
    
        cc.eventManager.addListener(this._touchListener, this);
    }
    

    【讨论】:

    • 这救了我!我看到的其他触摸事件不起作用,但它起作用了!
    猜你喜欢
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多