cocos creator 制作作砸金蛋

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.
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cocos Creator模拟金蛋3d旋转效果 | 附代码egg.zip // Learn TypeScript: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class Game extends cc.Component { @property Count: number = 5; @property(cc.Prefab) prefab: cc.Prefab = null; @property(cc.Node) nodeParent: cc.Node = null; private mEggs: cc.Node[] = []; // LIFE-CYCLE CALLBACKS: // onLoad () {} start () { } // update (dt) {} onClick(event, data){ switch(data){ case 'add':{ this.addEggs(); break; } case 'move':{ this.moveEggs(); break; } case 'stop':{ this.stopMoveEggs(); break; } } } addEggs(){ if(this.Count <= 0){ return; } this.mEggs = []; const N = 360 / this.Count; for(let i = 0; i < this.Count; i++){ let egg = cc.instantiate(this.prefab); let js = egg.getComponent('Egg'); js.setRadian(i * N * Math.PI / 180); js.updatePos(); egg.parent = this.nodeParent; this.mEggs.push(egg); } } moveEggs(){ for(let i = 0; i < this.mEggs.length; i++){ this.mEggs[i].getComponent('Egg').setMove(true); } } stopMoveEggs(){ for(let i = 0; i < this.mEggs.length; i++){ this.mEggs[i].getComponent('Egg').setMove(false); } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值