cocos Creator 引擎2.4.3
编辑工具HBuild X
目标:制作砸金蛋
项目目录结构:
项目最终效果
给出的代码:
eggAlert.js绑定在eggAlert上,代码如下:
cc.Class({
extends: cc.Component,
properties: {
closeN: cc.Node,
chuizi: cc.Node
},
onLoad() {
cc.vv.add_listen_touch_end(this.closeN, this, this.closeFun);
},
closeFun() {
this.node.active = false;
},
update(dt) {
if (cc.vv.egg) {
this.chuizi.active = false;
}
},
});
eggItem.js绑定在eggItem上,代码如下:
cc.Class({
extends: cc.Component,
properties: {
},
onLoad() {
this.view = {};
cc.vv.load_all_object(this.node, "", this.view);
cc.vv.add_listen_touch_end(this.node, this, this.clickEventFun);
},
start() {
if (cc.vv.egg) {
this.view['egg'].active = false;
this.view['eggD'].active = true;
} else {
this.view['egg'].active = true;
this.view['eggD'].active = false;
}
},
clickEventFun() {
if (!cc.vv.egg) {
cc.vv.egg = true;
this.view['egg'].active = false;
this.view['eggD'].active = true;
}
}
});
结语
代码很简单,欢迎加群一起学习cocos creator.若二维码过期可以微信号jjljzh.