module game {
/**
*Created by 渔歌烟火 on 2018/3/28.
* 字体缓动动画
*/
export class LabelEffect {
private static _instance:LabelEffect;
public static get instance():LabelEffect
{
if( null == LabelEffect._instance )
{
LabelEffect._instance = new LabelEffect();
}
return LabelEffect._instance;
}
/**
* @param target 显示对象
* @param options 例如{ time: 1500,initNum:100,num: 88888, regulator: 50 }
*/
public playEffect(target:any,options:any){
options = options || {};
if(options.initNum==options.num)return;
var time = options.time,//总时间--毫秒为单位
finalNum = options.num, //要显示的真实数值
regulator = options.regulator || 100, //调速器,改变regulator的数值可以调节数字改变的速度
step = (finalNum-options.initNum) / (time / regulator),/*每30ms增加的数值--*/
count = options.initNum, //计数器
initial = options.initNum;
var timer = setInterval(()=> {
count = count + step;
if(count >= finalNum&&options.initNum<finalNum) {
clearInterval(timer);
count = finalNum;
} if(count <= finalNum&&options.initNum>finalNum) {
clearInterval(timer);
count = finalNum;
}
//t未发生改变的话就直接返回
var t = Math.floor(count);
if(t == initial) return;
initial = t;
target.text = initial+"";
}, 30);
}
}
}

  调用:LabelEffect.instance.playEffect(target, { time: 1500, initNum: num, num: score, regulator: 50 })

twfont的更多相关文章

随机推荐

  1. Linux:Day17(上) gawk基础

    GNU awk: 文本处理三工具:grep,sed,awk grep,egrep,fgrep:文本过滤工具:pattern sed:行编辑器 模式空间.保持空间 awk:报告生成器,格式化文本输出: ...

  2. RequestMapper

    @RequestMapping(value = "/v1/getAllUrl", method = RequestMethod.POST) public Object getAll ...

  3. 面试7家,收到5个offer,我的Python就业经验总结 !

    *---------------------------------------人生处处有惊喜,背后却是无尽的辛酸苦辣.   Python找工作并不容易,老表面试了很多企业,总结了些宝贵经验! 一周转 ...

  4. swift学习 引入三方遇到的问题

    问题来源: 1.swift项目pods  MJRefresh 为了在swift正常使用 建了一个桥接文件 2.在项目中又使用了 SDWebImage 用于加载网络图片 根据说明加了Podfile一个  ...

  5. 小A的柱状图

    链接 [https://ac.nowcoder.com/acm/contest/549/H] 题意 [] 分析 很显然你必须找到该高度下往左右找到第一个高度比该位置小的.这个区间的宽*该高度.就当前能 ...

  6. ios之库Protobuf的使用

    https://blog.csdn.net/dangbai01_/article/details/81099001 (1)Protobuf是什么? Protobuf 即 google protocol ...

  7. 第二部分之Redis服务器(第十四章)

    Redis服务器复制和多个客户端建立网络连接,处理客户端发送的命令请求,在数据库中保存客户端执行命令所产生的数据. 一,命令请求的执行过程 客户端向服务器发送命令请求 set key value 服务 ...

  8. PHP细节,empty,is_null,isset,if()

    以下内容转载自http://wuxinjie.github.io/php-04/ 从下表可知,empty与if()完全相反,is_null与isset完全相反 isset是语句,is_null是函数, ...

  9. mycat入门--数据库分片

    配置mycat的用户名和密码: 连接mycat,就像连接mysql一样:

  10. Analysis Services features supported by SQL Server editions

    Analysis Services (servers) Feature Enterprise Standard Web Express with Advanced Services Express w ...