Trouble with Sprite Sheets


I am having trouble using Sprite Sheets, I am following one of Ray Wenderlich’s tutorials:

but of course I am porting it over to cocos2d-x.

So I translate his code:

- (id)init {

    if ((self=[super init])) {

        // Create our sprite sheet and frame cache
        _spriteSheet = [[CCSpriteSheet spriteSheetWithFile:@"sprites.png" 
            capacity:2] retain];
        [[CCSpriteFrameCache sharedSpriteFrameCache] 
        [self addChild:_spriteSheet];

        [self spawnCar];
        [self schedule:@selector(secondUpdate:) interval:1.0];

    return self;


to look like this:

// on "init" you need to initialize your instance
bool HelloWorld::init()
    // 1. super init first
    if ( !CCLayer::init() )
        return false;

    // Create our sprite sheet and frame cache
    _spriteSheet = CCSpriteSheet::spriteSheetWithFile("sprites.png", 2);

    CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();


    this->schedule(schedule_selector(HelloWorld::secondUpdate), 1.0f);

    return true;


The cocos2d-x code crashes on this line:

I attached my sprites.png and my sprites.plist files.

Any help is greatly appreciated. (0.5 KB)

sprites.png (3.8 KB)


What platform did you run on? It seems the file path of “sprites.png” is error.


Thanks for responding.

I am running on a MAC OS X Snow Leopard (10.6.latest as 2/2/2011). And I am running the app with the iPhone simulator through XCode with SDK version 4.2.


Looks like I have the same problem. I’m trying to add sprite sheet to shared frames cache and get BAD_EXC_ACCESS during xml reading.
It happens here(, line 195):

int result = xmlSAXUserParseMemory( &saxHandler, this, buffer, size );

if ( result != 0 )
   return NULL;

Actually it crashes bit later when trying to get access to xml data via null pointer(it should be NSDictionary with xml)

“result” value is 4. Don’t know what does this mean. Somebody know?

PLIST file was generated by zwoptex with “cocos2d” export option. I’ve add it to the resources and looks like it was correctly read in memory. But framework stuck on xml parsing…


Prev post was mine.
I’ve managed to fix this by renaming .plist file into .xml.


I’m the original poster.

Thanks for the work around, switching .plist to .xml works for me too.

I wonder whats going on, because I can see the calls working in the test project, but once I create my own project this problem happens. Maybe the cocos2d-x team can help with this when they get back from the Chinese New Year.

Again thanks, I have been annoyed by this for about a week.


I’ve been having the same problem. xcode converts plist files to a binary format, but it looks like the cocos2d-x code uses fread() which expects text. I think it might need to change to use the Core Foundation libraries:


Same problem here. Thanks for the workaround!
hope this will be fixed in the future…


Thanks to all for you.
Bug #349 is created for this discussion.
Invoking Core Foundation APIs may only work for iOS. I think we had better to find a way to support binary .plist files on both iphone & android.


I just wanted to say I had the same problem in XCode. I fixed it by right-clicking it in Resources > Get Info and changed its “File Type” to “text” used to be “text.plist.xml”. It seems it keeps the format inside the package. Works like a charm :slight_smile: