C++ equivalent of iOS instruction "if ((self = [super initWithSpriteFrameName:@"myimage.png"]))" ??

Hi,

In my class inhereting from CCSprite, I have got the following init method in my iOS code:

- (id)initWithAWorld:(b2World *)world {

    if ((self = [super initWithSpriteFrameName:@"myimage.png"])) {
        _world = world;
        //etc...
    }
    return self;
}

I replace this code in my C++ program by (nota: MyClass inherits from CCSprite):

bool MyClass::initWithAWorld(b2World *world)
{
    if(this->initWithSpriteFrameName("myimage.png"))
    {
        _world = world;
       //etc...
    }
    return true;

}

but it crashes on this->initWithSpriteFrameName(“myimage.png”)…

I saw the following threads on the forum but they didn’t allow me to solve my issue (perhaps I didn’t understand what is explained…):

http://www.cocos2d-x.org/boards/6/topics/191
http://www.cocos2d-x.org/boards/6/topics/4489

nota: I use Xcode. In your answer, please mention if I have to write the full path to the image ? (as mentioned in some of explanations in the above threads) If yes, what is the syntax with Xode:

initWithSpriteFrameName("j:/WorkTheGame/cocos2d/HelloWorld/Resource/myimage.png") ?
initWithSpriteFrameName("j/WorkTheGame/cocos2d/HelloWorld/Resource/myimage.png") ?
initWithSpriteFrameName("/WorkTheGame/cocos2d/HelloWorld/Resource/myimage.png") ?
initWithSpriteFrameName("./WorkTheGame/cocos2d/HelloWorld/Resource/myimage.png") ?
else ?

Thanks for your help (and Happy Christmas :))

  1. I guess your resource “myimage.png” hasn’t been packed in the app, hence it crashed.
  2. About full path, you can refer to the usage in HelloWorld or Tests, CCTextureCache will call CCFileUtils::fullPathFromRelativePath for input paramaters. So only input image file name here.