| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import library = require("../BiBeng/Library");
- export default class Utils {
- /**
- * 将(秒)格式化为(分:秒)
- * @param seconds 秒数
- */
- public static FormatSecToMinSec(seconds:number):string{
- let minute = Math.floor(seconds/60);
- let second = Math.floor(seconds%60);
- return (minute<10?'0':'')+minute+':'+(second<10?'0':'')+second;
- }
- /**
- * 加载SpriteFrame
- * @param url 资源地址(base64url)
- * @param callback 成功回调
- */
- public static LoadSpriteFrame(url: string, callback: (spriteFrame: cc.SpriteFrame) => void) {
- if (url.substring(0, 10).toLocaleLowerCase() === "data:image") {
- library.setImageBase64(url, (texture2D: cc.Texture2D) => {
- let spriteFrame = new cc.SpriteFrame(texture2D);
- if (callback instanceof Function) callback(spriteFrame);
- });
- } else if (url.startsWith("http")) {
- cc.loader.load({url: url, type: "jpg"}, (err, texture2D: cc.Texture2D) => {
- if (err) {
- console.error("cc load image fail", err);
- return;
- }
- let spriteFrame = new cc.SpriteFrame(texture2D);
- if (callback instanceof Function) callback(spriteFrame);
- });
- } else {
- cc.loader.loadRes(url, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
- if (err) return;
- if (callback instanceof Function) callback(spriteFrame);
- });
- }
- }
- }
|