[SOLVED] Custom CCNode Subclass didnt showed the sprite child

The idea is to make a game object, “Question”. Which is a CCNode that have an image and a string of question.

The Question Class :

Question* Question::initWithFile(char *fileName, int posX, int posY)
{

Question* question = new Question;   

// Add the image to the Question node
CCSprite* myImage = CCSprite::spriteWithFile(fileName);
myImage->setPosition(ccp(posX, posY));
question->addChild(myImage);

CCLog("Success");
return question;
}

void Question::setQuestion(char *theQuestion)
{
sprintf(dataQuestion,"%s",theQuestion);
}

Invoked in Game Class :

Question* question1 = Soal::initWithFile("questionImage1.png", 200, 200);
question1 ->setPosition(0,0);
stage->addChild(question1);

This code compiled without error, and the “Success” log showed up. But the image did not showed up. I hope my question can help other newbie in Cocos2D-X

Hi, Diori

I test the code you’ve posted and it works. The image shows up at (200, 200).
Could you pack your code in a HelloWorld for us to analyse?

Yinghui Peng wrote:

Hi, Diori
>
I test the code you’ve posted and it works. The image shows up at (200, 200).
Could you pack your code in a HelloWorld for us to analyse?

Hi, Yinghui thanks for you reply
I’ve solved it now. I forgot the child of my background image is set to 1. And the default index for the addChild when ignored is 0. So the image behind the background.
Thank you so much Yinghui :slight_smile: