我使用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;
...
}
答案 0 :(得分:2)
我这样实现它,它在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);
}