How to use CCLOG¶
CCLOG can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.
CCLOG is not as powerful as NSLog on OS X. You cannot use CCLog if you don’t know how to format output.
Turn on the Marcos¶
CCLOG is enabled while COCOS2D_DEBUG is defined as 1.
#define COCOS2D_DEBUG 1
For people wanting to check their preprocessor macros in visual studio, right click the project in the
project manager-> click properties-> select configuration properties-> C/C++ -> Preprocessor. You will have the preprocessor definitions in the right .
Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument:
CCLOG("Characters: %c %c", 'a', 65); CCLOG("Decimals: %d %ld", 1977, 650000L); CCLOG("Preceding with blanks: %10d", 1977); CCLOG("Preceding with zeros: %010d", 1977); CCLOG("Some different radixes: %d %x %o %#x %#o", 100, 100, 100, 100, 100); CCLOG("Floats: %4.2f %.0e %E", 3.1416, 3.1416, 3.1416); CCLOG("%s","A string");
CCLOG is not bound to Lua, you can use
cclog = function(...) print(string.format(...)) end cclog("float and int and string: %4.2f, %#x, %s", 3.1415926, 2014, "cocos2d-x"); print("you can use either print or cclog as you want"); print("another float is " .. 3.14 .. " another int is " .. 1024);
cocos2d: Characters: a A cocos2d: Decimals: 1977 650000 cocos2d: Preceding with blanks: 1977 cocos2d: Preceding with zeros: 0000001977 cocos2d: Some different radixes: 100 64 144 0x64 0144 cocos2d: Floats: 3.14 3e+00 3.141600E+00 cocos2d: A string
cocos2d: [LUA-print] float and int and string: 3.14, 0x7de, cocos2d-x cocos2d: [LUA-print] you can use either print or cclog as you want cocos2d: [LUA-print] another float is 3.14 another int is 1024