An easy way to output values ?

An easy way to output values ?
0.0 0


Hi all,
As I’m new with cocos2d-x development, I’m looking for an easy and fast method to output values (in editor or directly on screen, doesn’t matter).
I don’t find any function to output my x and y values of my CCPoint :frowning:
I’m looking for something like a PrintLine or something smarter than a printf…

[ solved ] CCLabelTTF With NSString and Array

Smarter than printf? printf is pretty smart…

printf( “Touch f,f\n”, touchPoint.x, touchPoint.y );

Appears in the output window (if you can’t see it, in xcode click View~~>Debug Area~~>Active Console).

Or to display something on screen make a label:

int your header:
CCLabelTTF m_label;

in your code init:
sprintf( m_str, “f, f,”, x, y );
m_label = CCLabelTTF::labelWithString(str, “Arial”, 24);
addChild( m_label, 0 );
m_label~~>setPosition );
and to change the text next update frame:
m_label~~>setString( str );


Ok I see :slight_smile:
Is there a function that makes a “toString” on my values to use the labelTTF method easily ? I see that it only takes a const char.


Oh yeah, my mistake - the string needs to be a constant/in memory, put that char str[20] in your header too, or do a char *str= new char[20] and remember to delete it. (I changed this in my comment above already).

And you can use CCStrings or std:string like this:

CCString *cs = new CCString( "Hello" );
m_label = CCLabelTTF::labelWithString( cs->m_sString.c_str(), "Arial", 24);

std::string *str = new std::string( "Hello" );
m_label = CCLabelTTF::labelWithString( str->c_str(), "Arial", 24);