ofreyre
September 11, 2014, 7:53pm
#1
Release notes docs of cocos2D-js v3 R02 say that now remote images can be loaded using cc.textureCache and cc.loader, but I have not been able to to it.
Maybe I´m missing some binding, I don´t know.
I’m using Cocos Code IDE v1.0.0.RC0, working on windows 7.
Thanks a lot
How did you use it, can you post some sample code ?
And from RC3, we have added a test case for remote image loading
var RemoteTextureTest = TextureCacheTestBase.extend({
_title:"Remote Texture Test",
_subtitle:"",
_remoteTex: "http://www.cocos2d-x.org/attachments/download/1508",
_sprite : null,
onEnter:function () {
this._super();
cc.textureCache.addImage(this._remoteTex, this.texLoaded, this);
},
texLoaded: function(texture) {
if (texture instanceof cc.Texture2D) {
cc.log("Remote texture loaded: " + this._remoteTex);
if (this._sprite) {
this.removeChild(this._sprite);
}
this._sprite = new cc.Sprite(texture);
this._sprite.x = cc.winSize.width/2;
this._sprite.y = cc.winSize.height/2;
this.addChild(this._sprite);
}
else {
cc.log("Fail to load remote texture");
}
}
});
ofreyre
September 15, 2014, 6:49pm
#4
Thanks very much for your reply.
I have tested with R03:
var RemoteText = cc.Layer.extend({
_remoteTex: "http://www.cocos2d-x.org/attachments/download/1508",
_sprite : null,
ctor:function() {
this._super();
},
onEnter:function () {
this._super();
cc.textureCache.addImage(this._remoteTex, this.texLoaded, this);
},
texLoaded: function(texture) {
cc.log("texLoaded: "+texture)
if (texture instanceof cc.Texture2D) {
cc.log("Remote texture loaded: " + this._remoteTex);
if (this._sprite) {
this.removeChild(this._sprite);
}
this._sprite = new cc.Sprite(texture);
this._sprite.x = cc.winSize.width/2;
this._sprite.y = cc.winSize.height/2;
this.addChild(this._sprite);
}
else {
cc.log("Fail to load remote texture XXX");
}
}
});
It seams as it loads the image but it lost it at some point because it sent texture = NULL to the texLoaded handler. This is the log:
debug server : client connected
JS: asyncListen…
JS: texLoaded: null (I added cc.log("texLoaded: "+texture))
JS: Fail to load remote texture
HTTP/1.1 200 OK
Content-Type: image/png
Connection: keep-alive
Status: 200 (HTTP status OK)
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
Content-Transfer-Encoding: binary
X-Runtime: 9
Content-Disposition: inline; filename=“2dh5-logo.png”
Content-Length: 54970 (I downloaded the image with browser and its 54k, just like this content-length)
Cache-Control: private
Server: nginx/1.0.15 + Phusion Passenger 3.0.11 (mod_rails/mod_rack)
Thanks
The log is quite odd, because it shows that the callback function is called before the texture loading
ofreyre
September 17, 2014, 1:50am
#6
Yes, all the part of the log:
HTTP/1.1 200 OK
Content-Type: image/png
Connection: keep-alive
Status: 200 (HTTP status OK)
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
Content-Transfer-Encoding: binary
X-Runtime: 9
Content-Disposition: inline; filename=“2dh5-logo.png”
Content-Length: 54970 (I downloaded the image with browser and its 54k, just like this content-length)
Cache-Control: private
Server: nginx/1.0.15 + Phusion Passenger 3.0.11 (mod_rails/mod_rack)
Is output after I stop the application.
During runtime the log outputs only:
debug server : client connected
JS: asyncListen…
JS: texLoaded: null
JS: Fail to load remote texture
I retried but can not reproduce the issue, can you tell me the exact steps to reproduce it?
And also, please try 3.0 Final version
If you are using cocos2d-x 3.0 rc2 or higher, please use Cocos Code IDE 1.0.0-rc2.
ofreyre
September 22, 2014, 4:00pm
#9
I’m using Cocos Code IDE 1.0.0-rc0, but with Cocos-js v3 RC3 framework