我使用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;
...
}
最佳答案
我是这样实现的,它在 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);
}
关于android - 在浏览器上工作时触摸设备不工作 [cocos2d-JS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25560474/