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