cocos-creator使用记录16_用户自定义监听事件

1.用户自定义监听事件
cc.game.on  //定义监听事件
cc.game.emit //通知监听事件调用


2.实例
Game.js------------
onLoad: function() {
//监听游戏结束
cc.game.on("game_over",function(){
this.gameOverNode.active = true;
},this);
},


Hero.js------------
destroySelf: function(){ //销毁自己
this.node.destroy();
cc.game.emit("game_over"); //通知游戏界面游戏结束
},


以上只是列举了一个游戏结束的事件,其他的还可以有
//.监听-金币变化事件
cc.game.on("get_coin",function(){
this.CoinLabel.string = cc.sys.localStorage.getItem("coint");          
},this);

猜你喜欢

转载自blog.csdn.net/haibo19981/article/details/80452519