| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- let library = {
- //数组元素位置替换
- 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<rate)
- {
- return true;
- }
- else
- {
- return false;
- }
- return;
- },
- openInWebview () {
- let ua = navigator.userAgent.toLowerCase()
- if (ua.match(/MicroMessenger/i) == 'micromessenger') { // 微信浏览器判断
- return false
- } else if (ua.match(/QQ/i) == 'qq') { // QQ浏览器判断
- return false
- } else if (ua.match(/WeiBo/i) == "weibo") {
- return false
- } else {
- if (ua.match(/Android/i) != null) {
- return ua.match(/browser/i) == null
- } else if (ua.match(/iPhone/i) != null) {
- return ua.match(/safari/i) == null
- } else {
- return (ua.match(/macintosh/i) == null && ua.match(/windows/i) == null)
- }
- }
- },
- indexOf (arr,item) {
- for (let i = 0; i < arr.length; i++) {
- if (arr[i] == item) return i;
- }
- return -1;
- },
- remove(arr, item) {
- let index = arr.indexOf(item);
- if (index > -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;
|