1

CCTexture2D and CCTextureCached do not seem to work. What is the best way to replace an image of a CCSprite(created from spritbuilder) with a UIImage(an image taken from the camera)?

James Webster
  • 31,873
  • 11
  • 70
  • 114
  • create a CGImage from the UIImage then init a sprite with that – CodeSmile Feb 16 '14 at 00:42
  • I did that but it still displays the old image that was present when I created it on spritebuilder. – user3314665 Feb 16 '14 at 23:14
  • I want to keep the same sprite not replace it – user3314665 Feb 17 '14 at 07:30
  • you can also change the texture of the existing sprite – CodeSmile Feb 17 '14 at 08:07
  • This is my code for it NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"]; UIImage* image = [UIImage imageWithData:imageData]; _hero = [[CCSprite alloc]initWithCGImage:image.CGImage key:nil]; but it still does not work – user3314665 Feb 17 '14 at 08:19
  • the texture may still be cached, use cctexturecaxhe remove message with @"image" as the key – CodeSmile Feb 17 '14 at 08:26
  • It says cctexturecache is undeclared... I tried this CCTexture *tex = [[CCTexture alloc]initWithCGImage:image.CGImage contentScale:40]; and then [_hero setTexture:tex]; but I cannot see the image again – user3314665 Feb 17 '14 at 08:40
  • Instead of "contentScale:40" try "contentScale:1". – maelswarm Feb 17 '14 at 08:58
  • It doesn't make a difference. The old image of the CCSprite is still present and I can't see the new Image – user3314665 Feb 17 '14 at 09:14
  • from the top of my head: [[CCTextureCache sharedTextureCache] removeTextureForKey:@"image"]; Allow Xcode autocomplete to help you with available "remove" methods or look into the class' header file (@interface) – CodeSmile Feb 17 '14 at 09:55
  • Isn't CCTextureCache gone for Cocos2d v3? – user3314665 Feb 17 '14 at 09:59

0 Answers0