Sprite from url

Hi all,

Wanted to share a class that I wrote, based on other forum posts.
I made a UrlSprite that downloads an image an scales it according to the aspect ratio to fit a specific size.

  • You can add a placeholder sprite to fade from when the image is not loaded yet.
  • You can set a callback when the image is downloaded.
  • You can enable/disable clipping to bounds.

The image is downloaded save in the writablepath() folder with a md5 encoding of the url. That’s why I have a md5 file. (I prefer to use cache directory on iOS instead of documents directory.
Hope someone can use it :smile:
Or maybe makes it better and adds it to cocos project.

UrlSprite* urlSprite = UrlSprite::create(myUrl, Size(100, 100), placeholderSprite);

Hope you like it,

Friendly regards,

Seppe

UrlSprite.zip (8.4 KB)

Awesome, Thanks for sharing

Hi, is good, but it is better to use cocos2d::network::HttpRequest for support all platform.