
我们可以在构造函数中添加触摸:
//在事件管理器中添加监听;
cc.eventManager.addListener({
//规定事件监听为 ONE_BY_ONE
event : cc.EventListener.touch_ONE_BY_ONE,
//允许触摸传递
swallowtouches : true,
//触摸开始ontouchBegan
ontouchBegan : this.ontouchBegan,
//触摸移动
ontouchmoved : this.ontouchmoved,
//触摸结束
ontouchended : this.ontouchended
},this);
//以上为添加触摸事件,下面使用触摸事件
ontouchBegan :function(touch,event)
{
var touches =touch.getLocation();
if(touches){
cc.log("touches");
}
},
ontouchmoved : function(touch,event)
{
cc.log("hello");
},
ontouchended :function(touch,event){
cc.log("world");
}
总结以上是内存溢出为你收集整理的【cocos2dx-js 学习分享 五】 触摸相应机制全部内容,希望文章能够帮你解决【cocos2dx-js 学习分享 五】 触摸相应机制所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)