当前位置: 首页 > 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)
  • “Material Design”设计规范在 ComponentOne For WinForm 的全新尝试!
  • Android优雅地处理按钮重复点击
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • happypack两次报错的问题
  • IE报vuex requires a Promise polyfill in this browser问题解决
  • java B2B2C 源码多租户电子商城系统-Kafka基本使用介绍
  • JavaScript服务器推送技术之 WebSocket
  • leetcode388. Longest Absolute File Path
  • Netty 框架总结「ChannelHandler 及 EventLoop」
  • overflow: hidden IE7无效
  • quasar-framework cnodejs社区
  • 使用Tinker来调试Laravel应用程序的数据以及使用Tinker一些总结
  • 适配mpvue平台的的微信小程序日历组件mpvue-calendar
  • 温故知新之javascript面向对象
  • 系统认识JavaScript正则表达式
  • 小程序滚动组件,左边导航栏与右边内容联动效果实现
  • 不要一棍子打翻所有黑盒模型,其实可以让它们发挥作用 ...
  • 长三角G60科创走廊智能驾驶产业联盟揭牌成立,近80家企业助力智能驾驶行业发展 ...
  • 数据可视化之下发图实践
  • ​iOS安全加固方法及实现
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • #include到底该写在哪
  • (3)选择元素——(17)练习(Exercises)
  • (博弈 sg入门)kiki's game -- hdu -- 2147
  • (二刷)代码随想录第16天|104.二叉树的最大深度 559.n叉树的最大深度● 111.二叉树的最小深度● 222.完全二叉树的节点个数
  • (翻译)Quartz官方教程——第一课:Quartz入门
  • (附源码)springboot车辆管理系统 毕业设计 031034
  • (附源码)springboot学生选课系统 毕业设计 612555
  • (附源码)计算机毕业设计SSM在线影视购票系统
  • .java 指数平滑_转载:二次指数平滑法求预测值的Java代码
  • .L0CK3D来袭:如何保护您的数据免受致命攻击
  • .NET DataGridView数据绑定说明
  • .net framework4与其client profile版本的区别
  • .net 设置默认首页
  • .NET/C# 使用反射注册事件
  • .NET精简框架的“无法找到资源程序集”异常释疑
  • .net中应用SQL缓存(实例使用)
  • .pub是什么文件_Rust 模块和文件 - 「译」
  • ::什么意思
  • @Autowired和@Resource的区别