Calling CSprite::initWithSpriteFrameName crash !

Maybe I am calling wrong this function but I have a crash ( the function is initWithSpriteFrameName).

PlayerEntity is derived from CCSprite;

bool PlayerEntity:: initWithPlayerImage ( void )
{

if ( true == this->initWithSpriteFrameName(“c:/WorkTheGame/cocos2d/HelloWorld/Resource/ship.png”) )
….

}

PS: I compiled on win32;

best regards,
Valentin

yes, call the wrong function
and “//”

I think it’s wrong with your code.
First, if you want use function initWithSpriteFrameName() to init your sprite.Your code should like this:

    // add frames from mypic.plist file.
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("mypic.plist");

    // use the FrameName in the mypic.plist file
    CCSprite* pPlayer = new CCSprite;
    pPlayer->initWithSpriteFrameName("ship.png");

Second, if you want init your sprite with a .png file,you shoud use function initWithFile().Your code should like this:

    // use the .png file to init your sprite
    CCSprite* pPlayer = new CCSprite;
    pPlayer->initWithFile("c:/WorkTheGame/cocos2d/HelloWorld/Resource/ship.png");

Hope it’s useful to you!

if the ship.png is a part of some.png, it should defined in a some.plist file, then you should load plist file first, like this:

// add frames from mypic.plist file to cache.
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("some.plist");

In your sprite class:

bool PlayerEntity:: initWithPlayerImage ( void ) {

if ( true == this->initWithSpriteFrameName("ship.png ") )
....

}

if you want init your sprite with a .png file,you shoud use function initWithFile().Your code should like this:

bool PlayerEntity:: initWithPlayerImage ( void ) {

if ( true == this->initWithFile("c:/WorkTheGame/cocos2d/HelloWorld/Resource/ship.png"))
....

}

Thank you,

I see now what I did wrong :slight_smile:

Hi Valentin,

Can you tell me what you finally used instead of:

if ( true == this->initWithSpriteFrameName(“c:/WorkTheGame/cocos2d/HelloWorld/Resource/ship.png”) )

I have got the same issue !

Thanks.