0
votes

In my game I initially create sprites using this code:

- (void)addSpritesForCookies:(NSSet *)cookies {
    for (BBQCookie *cookie in cookies) {
        NSString *directory = [NSString stringWithFormat:@"sprites/%@.png", [cookie spriteName]];
        CCSprite *sprite = [CCSprite spriteWithImageNamed:directory];
        sprite.position = [self pointForColumn:cookie.column row:cookie.row];
        [self.cookiesLayer addChild:sprite];
        cookie.sprite = sprite;
    }
}

This works perfectly fine, and the sprites display properly. All of the textures that I need are in a smart sprite sheet that I created in spritebuilder. Here is a screenshot of the structure in Spritebuilder, since I don't have enough reputation to post images here: https://www.evernote.com/shard/s30/sh/e1ea553f-a26c-4ecd-866b-551b50f14bd7/cc338b5ea3e557777a9a3acdeb0cd5ac

Then later on I need to change the texture on some of the sprites. I'm using the following code:

CCActionCallBlock *changeSprite = [CCActionCallBlock actionWithBlock:^{
            NSString *directory = [NSString stringWithFormat:@"sprites/%@.png", [combo.cookieB spriteName]];
            CCTexture *texture = [CCTexture textureWithFile:directory];
            combo.cookieB.sprite.texture = texture;
        }];

However, I just get these messages logged:

2015-01-17 12:22:09.294 BbqBlitz[65732:4875151] -[CCFileUtils fullPathForFilename:contentScale:] : cocos2d: Warning: File not found: sprites/Cupcake.png
2015-01-17 12:22:09.294 BbqBlitz[65732:4875151] cocos2d: Couldn't find file:sprites/Cupcake.png

What's weird is that I'm using exactly the same file path to initially create the sprites, which works fine. But now that I'm trying to create a texture its not working, and the sprites are just turning into black squares in my game.

I've already read this similar question: SpriteBuilder image file not found but from what I can tell the directory I'm using is correct.

What am I missing here? Thanks so much for any help!

1

1 Answers

0
votes

Try to load it without folder name

NSString *directory = [NSString stringWithFormat:@"%@.png", [combo.cookieB spriteName]];

It could be a part of sprite sheet after spriteBuilder, I suppose.