当前位置: 首页 > news >正文

【cocos creator】进度条控制脚本,支持节点进度条,图片进度条,进度条组件,和进度文字展示

进度条控制脚本,支持节点进度条,图片进度条,进度条组件,和进度文字展示
在这里插入图片描述
在这里插入图片描述


const { ccclass, property, menu } = cc._decorator;let text_type = cc.Enum({"20%": 0,"1/5": 1,"差值": 2,"自定义": 3,
});
let bar_type = cc.Enum({"Sprite": 0,"ProgressBar": 1,"Node": 2,
});@ccclass
@menu("自定义组件/进度条")
export default class barNode extends cc.Component {@property({type: cc.Sprite,visible() { return this.barType == bar_type.Sprite }})spriteBar: cc.Sprite = null;@property({type: cc.ProgressBar,visible() { return this.barType == bar_type.ProgressBar }})progressBar: cc.ProgressBar = null;@property({type: cc.Node,visible() { return this.barType == bar_type.Node }})nodeBar: cc.Node = null;@property({type: cc.Float,visible() { return this.barType == bar_type.Node }})max: number = 1;@property({type: cc.Float,visible() { return this.barType == bar_type.Node }})min: number = 0;@property(cc.RichText)barDesc: cc.RichText = null;@property(cc.Label)barDesc2: cc.Label = null;@property({type: cc.Enum(bar_type),displayName: "进度条类型"})barType = bar_type.Sprite;@property({type: cc.Enum(text_type),displayName: "进度文字类型"})textType = text_type["1/5"];_width = 0;protected onLoad(): void {}init(value, limit, bar_desc?) {let desc: string = bar_desc || "[0]";let percent = value / limit;percent = percent > 1 ? 1 : percent;if (this.spriteBar && this.barType == bar_type.Sprite) this.spriteBar.fillRange = percent;if (this.progressBar && this.barType == bar_type.ProgressBar) this.progressBar.progress = (percent < 0.1 && percent != 0) ? 0.1 : percent;if (this.nodeBar && this.barType == bar_type.Node) {this.nodeBar.width = (percent && percent * this.max < this.min) ? this.min : percent * this.max;}let str = "";switch (this.textType) {case 0: str = `${this.fixForce(percent * 100, 2)}%`desc = desc.replace("[0]", str);break;case 1: str = `${value}/${limit}`;desc = desc.replace("[0]", str);break;case 2: str = `${limit - value < 0 ? 0 : limit - value}`desc = desc.replace("[0]", str);break;case 3:desc = desc.replace("[0]", value);desc = desc.replace("[1]", limit);break;}if (this.barDesc) this.barDesc.string = desc;if (this.barDesc2) this.barDesc2.string = desc;}fixForce(count, fixTo): string {let a = (count + "").split(".");let b = a[0];if (a.length > 1) b = a[0] + "." + a[1].slice(0, fixTo);if (b == "0.00" && count != 0) {if (a.length > 1) b = a[0] + "." + a[1].slice(0, 4);}return b;}
}

相关文章:

  • AI整体架构设计4:理解AI云原生
  • 活动预告|来 GIAC 大会听大数据降本利器:AutoMQ 基于云原生重新设计的 Kafka
  • 92.网络游戏逆向分析与漏洞攻防-游戏技能系统分析-利用哈希表实现快速读取文本内容
  • Typescript高级: 深入理解工厂函数类型
  • 【计算机毕业设计】基于SSM++jsp的实验室耗材管理系统【源码+lw+部署文档】
  • Day02:LeedCode977. 有序数组的平方 209.长度最小的子数组 59.螺旋矩阵II
  • 《Qt》使用Windeployqt发布程序
  • 【yolo 项目】
  • el-radio-group 选择一个,全部选中 解决方案
  • [蓝桥杯 2020 省 A1] 超级胶水
  • 顶顶通呼叫中心中间件-自动外呼输入分机号(比如隐私号)(mod_cti基于FreeSWITCH)
  • 信息泄露--注意点点
  • AI大模型应用开发实践:3.使用 tiktoken 计算 token 数量
  • SQL 面试系列(一)【留存率问题】
  • 【论文笔记】Attention is All You Need(NIPS’17)
  • 网络传输文件的问题
  • __proto__ 和 prototype的关系
  • CSS实用技巧干货
  • export和import的用法总结
  • JAVA之继承和多态
  • Redis学习笔记 - pipline(流水线、管道)
  • Transformer-XL: Unleashing the Potential of Attention Models
  • UMLCHINA 首席专家潘加宇鼎力推荐
  • vuex 学习笔记 01
  • 前端之Sass/Scss实战笔记
  • 前端自动化解决方案
  • 前嗅ForeSpider中数据浏览界面介绍
  • 我从编程教室毕业
  • 线上 python http server profile 实践
  • 用element的upload组件实现多图片上传和压缩
  • - 语言经验 - 《c++的高性能内存管理库tcmalloc和jemalloc》
  • 最简单的无缝轮播
  • 移动端高清、多屏适配方案
  • ​【原创】基于SSM的酒店预约管理系统(酒店管理系统毕业设计)
  • ​Linux Ubuntu环境下使用docker构建spark运行环境(超级详细)
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • #14vue3生成表单并跳转到外部地址的方式
  • (js)循环条件满足时终止循环
  • (webRTC、RecordRTC):navigator.mediaDevices undefined
  • (zhuan) 一些RL的文献(及笔记)
  • (接口封装)
  • (十七)devops持续集成开发——使用jenkins流水线pipeline方式发布一个微服务项目
  • (续)使用Django搭建一个完整的项目(Centos7+Nginx)
  • *上位机的定义
  • ./mysql.server: 没有那个文件或目录_Linux下安装MySQL出现“ls: /var/lib/mysql/*.pid: 没有那个文件或目录”...
  • .md即markdown文件的基本常用编写语法
  • .NET C#版本和.NET版本以及VS版本的对应关系
  • .net core 6 集成 elasticsearch 并 使用分词器
  • .net mvc部分视图
  • .net生成的类,跨工程调用显示注释
  • ::
  • @KafkaListener注解详解(一)| 常用参数详解
  • [ 手记 ] 关于tomcat开机启动设置问题
  • [autojs]autojs开关按钮的简单使用
  • [AX]AX2012开发新特性-禁止表或者表字段