fish potato
fish potato

Reputation: 5629

Cocos2D: Create sprite from a file in documents directory

What is the best way to create instance of CCSprite from downloaded image file?

I would like to implement downloadable additional contents in my Cocos2D game.

The way I used is

  1. Create UImage from a downloaded image.
  2. Create CCTexture2D from UIImage.
  3. Create CCSprite from CCTexture2D.

If you know more smart way, please let me know.

Upvotes: 1

Views: 1174

Answers (2)

ArunGJ
ArunGJ

Reputation: 2683

If you have a UIImage named img;

sprite can be created by

CCSprite *s = [CCSprite spriteWithCGImage:img.CGImage key:@"image"];

Upvotes: 2

CodeSmile
CodeSmile

Reputation: 64477

Have a look at my tutorial How to Download (only) Modified Files from a Webserver. I used this to build a Cocos2D Webcam Viewer and contains example code for downloading files via NSData, saving it to the documents directory and creating a texture/sprite from the downloaded image file.

Upvotes: 1

Related Questions