Cocos Creator 3.4.2 实现滚动数字效果

资源下载地址:CocosCreator3.4.2实现滚动数字效果-Typescript文档类资源-CSDN下载

使用基本组件实现滚动数字效果。

一、节点结构

 二、代码

	callback(button: Button){
		// 随机生成一个1-100000的随机数
		var newNum:Number=Math.round(Math.random()*100000);
		var oriNum=this.num;
		this.num=newNum;
		console.log(newNum);

		var i=0;
		while( oriNum > 0 || newNum > 0 ){
			
			var before = oriNum%10;
			var after = newNum%10;

			if(oriNum>0) oriNum = (oriNum-before)/10;
			if(newNum>0) newNum = (newNum - after)/10;
			
			var dif=50.4* (after-before);
			console.log(after-before);
			cc.tween(this.numberLayout.children[i].getChildByName("Layout"))
				.by(0.5,{ position : cc.Vec3(0,dif,0)})
				.start();
			i++;
		}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 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
发出的红包

打赏作者

swhqq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值