Cocos Creator模拟射箭效果shoot.zip // Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/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] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { txtGrade: cc.Label, txtTime: cc.Label, btnStart: cc.Button, nodeBeat: cc.Node, }, // LIFE-CYCLE CALLBACKS: onLoad () { this._lefttime = 10; this._grade = 0; this.nodeBeat.active = false; }, start () { this.nodeBeat.on(cc.Node.EventType.TOUCH_START, event => { this.nodeBeat.scale = 1.1; }); this.nodeBeat.on(cc.Node.EventType.TOUCH_END, event => { this.nodeBeat.scale = 1.0; this._grade++; this.txtGrade.string = `面长${this._grade}米`; }); }, // update (dt) {}, updateGrade(){ if(cc.sys.platform == cc.sys.WECHAT_GAME){ let max = cc.sys.localStorage.getItem('max_grade'); if(max != null && max < this._grade){ cc.sys.localStorage.setItem('max_grade', this._grade); let KVDataList = [{key:'grade', value: this._grade.toString()}]; wx.setUserCloudStorage({ KVDataList: KVDataList, success: res => { console.log('success', res); }, faile: res => { console.log('faile', res); } }); } } }, startGame(){ this.btnStart.node.active = false; this.nodeBeat.active = true; this._lefttime = 10; this._grade = 0; this.txtGrade.string = `面长${this._grade}米`;; this.txtTime.string = `剩余:${this._lefttime}秒`; this.schedule(this.onTimerCallback, 1); }, onTimerCallback(){ this._lefttime--; this.txtTime.string = this._lefttime; this.txtTime.string = `剩余:${this._lefttime}秒`; if(this._lefttime <= 0){ this.unschedule(this.onTimerCallback); this.btnStart.node.active = true; this.nodeBeat.active = false; this.updateGrade(); } }, onClick(event, data){ switch(data){ case 'start':{ this.startGame(); break; } case 'back':{ cc.director.loadScene('main'); break; } } }, });
- 1
- 粉丝: 425
- 资源: 40
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python的PCA人脸识别算法的原理及实现代码详解+源码+详细代码解析+开发文档+数据(毕业设计&课程设计&项目开发)
- Decision tree20240105(1).ipynb
- zuoyezuoyezuoye
- zuoyezuoyezuoye
- 机械设计电机转子装配设备sw22非常好的设计图纸100%好用.zip
- 作业作业作业作业作业作业
- xdotool.c
- RLMD鲁棒性局部均值分解信号分量可视化(Matlab完整源码和数据)
- Screenshot_2024-04-26-17-17-26-36_9d26c6446fd7bb8e41d99b6262b17def.jpg
- 6.0版本超广角文件+教程使用MT管理器打-7.zip