2015-11-28 128 views
1

我在使用cocos2d js 3.9從IOS上的url加載圖像時出現錯誤。在網絡平臺上,它正確加載,但在Android或IOS,它不會加載,這是我的代碼加載Cocos2d js 3.9從URL加載圖像

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

希望這將有助於未來的追隨者。

從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. 
    } 

}