來源http://blog.csdn.net/nynyvkhhiiii/article/details/50820810
直接上代碼
varMsgBoxLayer = cc.LayerColor.extend({
sprite:null,
ctor :function(color, width, height){this._super(color, width, height);this._touchListener = cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches:true,
onTouchBegan:function(){returntrue;
}
});
cc.eventManager.addListener(this._touchListener,this);// 添加你的UI布局returntrue;
},
onExit :function(){if(this._touchListener) {
cc.eventManager.removeListener(this._touchListener,1);this._touchListener =null;
}
}
});
使用方法:
varmsgBox=newMsgBox(cc.color(0,0,0,0),800,600);this.addChild(msgBox);
這里有幾個(gè)知識(shí)點(diǎn):
1 cc.EventListener.create 官方自帶的觀察者模式,使用起來非常方便
2 event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
這兩個(gè)參數(shù)保證了層層傳遞,并且以本導(dǎo)員就吞噬掉touch事件们童,不再往下傳遞拍鲤,以達(dá)到屏蔽下層的目的。
3 在退出前別忘了做清理工作
https://www.processon.com/i/568c6ea4e4b0e51d149a085f
這個(gè)網(wǎng)站解決了大家開始設(shè)計(jì)階段的問題憋沿,輕量級(jí)的各種設(shè)計(jì)模型旺芽,強(qiáng)烈推薦