Cocos Creator 开发实战——数字滚动

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cocos Creator 中可以使用动作(Action)来创建数字滚动效果。下面是一个简单的示例代码: 1. 创建一个空节点,将它命名为“NumberRoller”。 2. 在“NumberRoller”节点下创建三个 Label 节点,分别命名为“Num1”、“Num2”、“Num3”。 3. 在“NumberRoller”节点上添加一个脚本组件,将以下代码添加到脚本中: ```javascript cc.Class({ extends: cc.Component, properties: { startValue: 0, endValue: 999, duration: 2, interval: 0.05, num1: cc.Label, num2: cc.Label, num3: cc.Label }, start () { this.num1.string = this.startValue; this.num2.string = this.startValue; this.num3.string = this.startValue; this.schedule(this.updateValue, this.interval); }, updateValue () { let value1 = Math.floor(Math.random() * 10); let value2 = Math.floor(Math.random() * 10); let value3 = Math.floor(Math.random() * 10); let valueSum = value1 * 100 + value2 * 10 + value3; let currentValue = parseInt(this.num3.string) + valueSum; if (currentValue > this.endValue) { currentValue = this.endValue; this.unschedule(this.updateValue); } this.num1.string = this.num2.string; this.num2.string = this.num3.string; this.num3.string = currentValue; } }); ``` 4. 在“NumberRoller”节点上配置脚本组件的属性,包括起始值(startValue)、结束值(endValue)、动画时间(duration)和数字变化的时间间隔(interval)。 5. 运行游戏,可以看到数字滚动的效果。 这只是一个简单的数字滚动效果示例,你可以根据你的实际需求进行修改和扩展。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值