Teguh Prabowo
Teguh Prabowo

Reputation: 31

Touch on device not working, while working on browser [cocos2d-JS]

Im using cocos2d-js to make the game and I try it on the browser, it run well, all the touch function is working, but when i compile it to android device the touch function is not working at all.

I register the touch with:

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

and implement it with:

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

Upvotes: 2

Views: 1104

Answers (1)

Michael
Michael

Reputation: 7113

I implement it like this and it works fine in WEB, Android and 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);
}

Upvotes: 3

Related Questions