I am trying to call a random static sprite from my plist. In this case it is a collectable orb, I have 4 images that I would like to randomly pick from named orb_0.png through to orb_3.png
I can call a single file image using and all is dandy.
- (CCSprite *)sprite {
if(_sprite == nil) {
_sprite = [CCSprite spriteWithSpriteFrameName:@"orb_0.png"];
However when I use the following code instead which is asking for the image but doesnt display them;
int randomOrb = rand( ) % 4;
_sprite = [ CCSprite spriteWithFile:[ NSString stringWithFormat:@"orb_%d.png", randomOrb]];
What I get in the debugger says the images cannot be found repeatedly.
2014-04-25 18:58:16.322 MadScientist[2210:60b] cocos2d: CCFileUtils: Warning file not found: orb_0-hd.png
2014-04-25 18:58:16.323 MadScientist[2210:60b] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2014-04-25 18:58:16.323 MadScientist[2210:60b] cocos2d: Couldn't add image:orb_0.png in CCTextureCache
2014-04-25 18:58:16.323 MadScientist[2210:60b] cocos2d: CCFileUtils: Warning file not found: orb_3-hd.png
2014-04-25 18:58:16.323 MadScientist[2210:60b] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2014-04-25 18:58:16.324 MadScientist[2210:60b] cocos2d: Couldn't add image:orb_3.png in CCTextureCache
Try sprite = [CCSprite spriteWithImageNamed:[NSString stringWithFormat:@"orb%d.png", randomOrb]]; That shoudl solve your problem.