1 Star 0 Fork 7

MrMriacle/cocos_creator_proj_base

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util.ts 1.58 KB
一键复制 编辑 原始数据 按行查看 历史
caochao 提交于 2019-05-15 10:14 +08:00 . 更新代码
let handler_pool:handler[] = [];
let handler_pool_size = 10;
//用于绑定回调函数this指针
export class handler
{
private cb:Function;
private host:any;
private args:any[];
constructor(){}
init(cb:Function, host = null, ...args)
{
this.cb = cb;
this.host = host;
this.args = args;
}
exec(...extras)
{
this.cb.apply(this.host, this.args.concat(extras));
}
}
export function gen_handler(cb:Function, host:any = null, ...args:any[]):handler
{
let single_handler:handler = handler_pool.length < 0 ? handler_pool.pop(): new handler()
//这里要展开args, 否则会将args当数组传给wrapper, 导致其args参数变成2维数组[[]]
single_handler.init(cb, host, ...args);
return single_handler;
}
export function strfmt(fmt:string, ...args:any[])
{
return fmt.replace(/\{(\d+)\}/g, (match:string, argIndex:number) => {
return args[argIndex] || match;
});
}
export function extend(target, ...sources) {
for (var i = 0; i < sources.length; i += 1) {
var source = sources[i];
for (var key in source) {
if (source.hasOwnProperty(key)) {
target[key] = source[key];
}
}
}
return target;
}
export function createBreathAction(node:cc.Node, min = 0.9, max = 1.1)
{
const action = cc.repeatForever(cc.sequence(cc.scaleTo(0.6, max), cc.scaleTo(0.6, min)));
node.runAction(action);
}
export function destroyBreathAction(node:cc.Node)
{
node.stopAllActions();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mrmriacle/cocos_creator_proj_base.git
git@gitee.com:mrmriacle/cocos_creator_proj_base.git
mrmriacle
cocos_creator_proj_base
cocos_creator_proj_base
master

搜索帮助