let library ={ formatSeconds(value) { let result = parseInt(value); // let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600); // let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60)); let m = Math.floor((result / 60 % 60)) < 10 ? '' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60)); let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60)); let res = ''; // if(h !== '00') res += `${h}h`; // if(m !== '00') res += `${m}min`; // res += `${s}s`; // if(h !== '00') res += `${h}:`; res += `${m}:`; res += `${s}`; return res; }, randomInt(min, max){ return Math.floor(Math.random() * (max+1 - min)) + min; }, getRandom(start, end, fixed=0) { //fixed 保留几位小数 let differ = end - start let random = Math.random() return (start + differ * random).toFixed(fixed) }, removeObj(arr,obj) { let index = this.indexOf(arr,obj); if (index > -1) { arr.splice(index, 1); } }, indexOf(arr,obj) { for (var i = 0; i < arr.length; i++) { if (arr[i] == obj) return i; } return -1; }, insert(arr,index, item) { arr.splice(index, 0, item); }, //数组元素位置替换 swapArray: function(arr, index1, index2) { arr[index1] = arr.splice(index2, 1, arr[index1])[0]; return arr; }, swapLeft : function(arr) { let element = arr.shift(); arr.push(element); }, //生成指定范围随机整数 randomFromIntRange: function(min, max) { return Math.floor(Math.random() * (max - min)) + min; }, happenRate: function(rate) { let result = this.randomFromIntRange(0,100); if(result -1) { arr.splice(index, 1); } }, setImageBase64(base64Url,callback){ let img = new Image(); img.src = base64Url; img.onload = function(){ let texture = new cc.Texture2D(); texture.initWithElement(img); texture.handleLoadedTexture(); if (callback) callback(texture); } }, }; module.exports = library;