Html; cocos2d-x; Is it possible to init a cc.Sprite from a URL?

hi all,

Is it possible to initialise a cc.Sprite from a URL of an image rather than from the built in resources?

I want to use the Facebook user image for my high score table.

thanks again,

LB

Yes, of course

I would like to do the same thing, could you give an example of how to do this ?

Thanks in advance!

In c++ and obj-c you need to download the data and do some tricks.
I thought there would be something similar in JS, but it is quite simple
really. Probably the reason for watson’s terse reply. :)
var mySprite = cc.Sprite.create;
Or like me you want to change this for an already created sprite:

var myUrl = “http://someurl/someimage.jpg”);
var tex = cc.TextureCache.getInstance().addImage(myUrl);
this.mySprite.setTexture(tex);

Hope this helps

LB

I did not know you could do this in cocos2d-html5, is really very simple. I would like to do this in multiplatafrom compatible, but I have to create my own JS binding in c++ and obj-c to do this. :frowning:

Thanks for the tip my friend :wink:

for the web, you can put them in DOM elements, if you want to go the pure Cocos2d way for JSB, there is no api currently for that. it requires that you have a fully loaded sprite to draw. you must write your own img loading code

Ok, but how is possible to load from an external url? For example i’d like to load facebook photo profile without passing by my own server and using bandwidth for nothing.

Hi
Did you solve this problem?

This code is not work!

var mySprite = cc.Sprite.create(“http://a1135.phobos.apple.com/us/r30/Purple6/v4/d3/4b/46/d34b4623-1285-2ee0-848a-78be0fe7e882/icon.png”);
mySprite.setPosition(cc.p(winSize.width / 2,120));
this.rootNode.addChild(mySprite,1);

var myUrl = “http://a1135.phobos.apple.com/us/r30/Purple6/v4/d3/4b/46/d34b4623-1285-2ee0-848a-78be0fe7e882/icon.png”;
var tex = cc.TextureCache.getInstance().addImage(myUrl);
var sprite = cc.Sprite.createWithTexture(tex);
sprite.setPosition(cc.p(winSize.width / 2,240));
this.rootNode.addChild(mySprite,1);