I dont know how to handle CCLog…
Can someone just let me know that How can I CCLog a CCArray Like —-
CCArray array;
CCLog;
Like——
NSArrayarray;
NSLog("%
", array);
I dont know how to handle CCLog…
Can someone just let me know that How can I CCLog a CCArray Like —-
CCArray array;
CCLog;
Like——
NSArrayarray;
NSLog("%
", array);
No, you should loop CCArray and use CCLog to output each element.
like what would be the printed variable type?? What should I cast while on printing??
CCSprite balloon;
CCArrayarray = balloon->getChildren();
for (int i=0; icount(); ++i){
CCLog(“%???”, array ->objectAtIndex(i));
}
You can only use CCLog like printf, you should format the output.
Actually the problem is I dont know the format what CCArray actually includes with getChildren(). What should I print or CCLog if I dont now the variable type??
Like:
int a[10];
for (int i=0; icount(); **i){
CCLog);
}
Bt what is the type of:
CCSprite balloon;
CCArrayarray = balloon->getChildren;
for ;**i){
CCLog("*+%?+*", array ->objectAtIndex);
}
Can u illustrate with some example code
I see, you can not use CCLog if you don’t know how to format output.
It is not such powerful as NSLog.
how to use cclog to print an object,like ccsprite or something? in cocos2d, we can use clog("object = %
", object); how to convert it to cocos2d-x?thank you
well you allways can use c++ templates
see simple example to print CCArray by T type class
// in header file
template
void printArray(CCArray* arr)
{
CCObject *aGemIt = NULL;
CCARRAY_FOREACH(arr,aGemIt)
{
T *aGem = static_cast(aGemIt);
int col = aGem->getColNum();
int row = aGem->getRowNum();
CCLOG("col:%d row:%d",col,row);
}
}
then call this function like this :
Gem is class
pUT->printArray(nextArray);
and to print CCDictionary
template
void printDictionary(CCDictionary* dic)
{
CCDictElement* pElement = NULL;
CCDICT_FOREACH(dic, pElement)
{
T* pSubClassObj = (T*)pElement->getObject();
std::string oneStrKey = pElement->getStrKey();
CCLOG("oneStrKey:%s",oneStrKey.c_str());
}
}
and call it like this:
pUT->printDictionary(pGemsDictionary);
also this is for version stable version 2.1.5
There is PrettyPrinter class in cocos2dx 3.0 already.