addspriteframeswithfile() or spriteFrameByName() error?

I’ve been stuck on this problem for the past 2 days. I am trying to use a plist file to load a sprite from a spritesheet. I first try it with the files and code provided by the author of the tutorial I’m working with. It works fine. But when I substitute my plist file and my sprite name into the code, it gives me a null pointer exception. The author’s plist file is, “mole.plist” and mine is “myspritesheet.plist.” The author’s sprite key is “a0001.png” while mine is “blue.png”. The changes to the code is as below:

CCString* file = (Utils::getArtScaleFactor() > 1) ? CCString::create(“myspritesheet.plist”) : CCString::create(“myspritesheet.plist”);
CCSpriteFrameCache::sharedSpriteFrameCache()>addSpriteFramesWithFile);
In my sprite cpp file, I load the sprite from the spritesheet with the following key:
this
>setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(“blue.png”));

The error I get is the standard null pointer exception:

Fatal signal 11 (SIGSEGV) AT 0x00000028 (code=1), thread 707 (Thread-81)

  • My theory of the problem is that the code is able to load the plist file but it is unable to use the key (blue.png) to load my sprite from the spritesheet. I have gone into both plist files to compare the author’s plist code with mine and there is little differences. I am frustrated now with not being able to understand how spriteFrameByName() retrieves the sprite from the spritesheet with the key I provide.

  • There is a difference in that the author uses a pvr.ccz file to load his sprite in his plist file from his spritesheet while I use a .png file (blue.png). Does that make any difference? My understanding of a pvr.ccz file is that it is just a compressed file. Am I using the right method, spriteFrameByName() to retrieve my sprite?

I do this, these are just pieces I dont do this in this linear order

if (screenSize.width > mediumResource.size.width)
    {
        //Utils::LogText("Large Resource");
        searchPaths.push_back(largeResource.directory);
        setIsIPad(true);
        setIsRetina(true);
        setIsIPhone(false);
        //getDirector()->setContentScaleFactor(screenSize.width/designResolutionSize.width);
        //pDirector->setContentScaleFactor(largeResource.size.height/designResolutionSize.height);
        //pDirector->setContentScaleFactor(largeResource.size.height/frameSize.height);
        //pDirector->setContentScaleFactor(2);
    } 

[snip…]

getDirector()->setContentScaleFactor(screenSize.width/designResolutionSize.width);
    getFileUtils()->setSearchPaths(searchPaths);

// setup Sprite Cache/sprite sheet.
    _spritecache = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache();
    setSpriteCache(_spritecache);
    getSpriteCache()->addSpriteFramesWithFile("sprites.plist");

Jason Slack-Moehrle, I don’t understand what you did. Can you explain further?

I have gone further in the analysis of this problem and taken a look at the source code for addSpriteFramesWithFile(const char pszPlist).
No where in this source code does it show how the code deals with searching the plist file for the appropriate sprite that you want to display. Unless it is the following code:
Dictionary
metadataDict = (Dictionary*)dict->objectForKey(“metadata”);

So, is the code creating a Dictionary object, and then loading into the object the key (sprite file) that you want to display? I want to see the actual code that searches for the sprite in my spritesheet and then loads it to the game. Did I find the right source code? Or is it some where else?

I think that reading from a .plist has to result in a dictionary as this is OS X and before I used cocos2d-x I would read .plists into an NSDictionary.