In the small game of cocos2d-x, the char * type string needs to be forcibly converted to void * pointer type, passed to the callback function through cccallfuncnd.
It is possible to find this:
// (A) is created using a string in double quotation marks.
Enemy * enemy = enemy: Create (this, "enemy/enemy2r.png ");
...
// (B) initialize
_ Bornaction = ccsequence: Create (ccanimate: Create (blastanimation ),
Cccallfuncnd: Create (this, callfuncnd_selector (tank: borncallback), (void *) filename ),
Null );
...
// (C) callback function
Char * STR = (char *) data;
The above method is acceptable. However, if you replace (a) with the following string:
Char STR [64] = {0 };
Sprintf (STR, "enemy/enemy1_dr.png", random );
Enemy * enemy = enemy: Create (this, STR );
In this case, the data obtained in the callback function is empty (for unknown reasons, do not spray the data ).
You can convert char * to STD: string * and then to void *. The data obtained by the callback function is normal. As follows:
_ Bornaction = ccsequence: Create (ccanimate: Create (blastanimation ),
Cccallfuncnd: Create (this, callfuncnd_selector (tank: borncallback), (void *) (new STD: string (filename ))),
Null );
...
// Callback
STD: string * STR = (STD: string *) data)-> c_str ();
The converted data will be normal. I do not know the specific reason. I guess there may be some differences between char [], char *, and "ABC.