如何写promise 像 cc.loader.load

image

调用这个function 可以读取icon(cocos内部的icon),但问题是,我没有办法确保他读取完成了,可以回传讯息,请问promise要怎么写?

ps:texture.loaded可以确认他已读取完,但光是这样,我只能开个schdule一直反覆跑到loaded是true才unschdule

urlToSpriteframe() {

    var dataURL = "./favicon.ico" + "?t=" + Date.now();

    var img = new Image();

    var texture = new cc.Texture2D();

    img.src = dataURL;

    texture.initWithElement(img);

    texture.handleLoadedTexture();

    this.sprite.spriteFrame.setTexture(texture)

    cc.log("loadingComplete");

}

image好像有个onLoad回调吧,用这个可以。


监听’load’

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。