addspriteframeswithfile() or spriteFrameByName() error?

addspriteframeswithfile() or spriteFrameByName() error?
0.0 0


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”);
In my sprite cpp file, I load the sprite from the spritesheet with the following key:

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");



// setup Sprite Cache/sprite sheet.
    _spritecache = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache();


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:
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.