Search code examples
c++iosxcodecocos2d-x

Assertion failed Invalid spriteFrameName


I am building a game using Cocos2dx. I have a sprite sheet and animation plist that specifies where all the images are.

For some reason when loading my game I get the following error:

(char [256]) msg = "Invalid spriteFrameName: PlayButton.png"

It is coming from line 159 of CCSprite.cpp:

CCSprite* CCSprite::createWithSpriteFrameName(const char *pszSpriteFrameName)
{
    CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pszSpriteFrameName);

#if COCOS2D_DEBUG > 0
    char msg[256] = {0};
    sprintf(msg, "Invalid spriteFrameName: %s", pszSpriteFrameName);
    CCAssert(pFrame != NULL, msg);
#endif

    return createWithSpriteFrame(pFrame);
}

I checked in my .plist and I do have an entry for PlayButton.png, so I have no idea why it says it is invalid.

That method is being called from the MainMenu::init() method:

fileName = (CCString*)sc->imageDict->objectForKey("GUI_StartButton-image");
CCSprite *startGameSprite = CCSprite::createWithSpriteFrameName( fileName->m_sString.c_str() ); <--- CRASHING HERE

What could be causing this?


Solution

  • Maybe you can see the following message in your log console

    cocos2d: SpriteFrameCache: Frame 'PlayButton.png' not found
    

    and if that's true then you have to load your spritessheet :

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("spritess‌​heet.plist", "spritesheet.png");