androidc++stringcocos2d-xcclabelttf

Trying to set up a CCLabelTTF with an integer as part of it's string in Cocos2d-X C++


So in Objective-C with Cocos2d, I'd use a NSMutableString with format to put a variable (score) into a string. I'd take that string and use a CCLabel to place it on the screen.

Using Cocos2D-x, I'm having trouble finding a way to get this result. A simple example would be great. Thanks!


Solution

  • int score = 35;
    float time = 0.03;
    char* name = "Michael";
    char text[256];
    sprintf(text,"name is %s, time is %.2f, score is %d", name, time, score);
    CCLabelTTF* label = CCLabelTTF::labelWithString(text,"Arial",20);
    this->addChild(label);