我尝试使用cocos2d js 3.9在IOS上从url加载图像时出错。在网络平台上,它正确加载,但在Android或IOS上,它没有加载,这是我的加载代码
var avatarLink = "http://i81.photobucket.com/albums/j223/drawkbox/cocos2dx_portrait.png";
var self = this;
cc.loader.loadImg(avatarLink,{isCrossOrigin : true}, function(err, texture){
var sprite = new cc.Sprite(texture);
sprite.setPosition(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
self.addChild(sprite);
});
答案 0 :(得分:0)
希望这将有助于未来的粉丝。
从URL加载图像的另一种方法是textureCache。
cc.textureCache.addImageAsync(URL, function(texture) {
if (texture instanceof cc.Texture2D) {
var sprite = new cc.Sprite(texture);
//Add this sprite anywhere you want
}
else {
cc.TextureCache.getInstance().removeAllTextures();
// Clear textureCache once it's done.
}
}