Environment: windows7, vs2010, cocos2d-1.0.1-x-0.12.0, cygwin, Eclipse, Android sdk4.0.3, ndk r7b
Developed on Vs and transplanted to Android.
20120718
The foreach operation of ccarray:
Problems with cocos2d-x local notification calls ccnotificationcenter
In the registered postnotification message function, you cannot call addobserver any more. This may cause ccarray expansion of the ccnotificationobserver object, resulting in a new memory address for ccarray and the first pointer for ccarray, when the postnotification function is returned after execution, it is inconsistent with the first ccarray pointer, leading to memory read errors.
observer->performSelector
Is the registered message callback function. You cannot add or delete custom messages in this function.
void CCNotificationCenter::postNotification(const char *name, CCObject *object){ CCObject* obj = NULL; CCARRAY_FOREACH(m_observers, obj) { CCNotificationObserver* observer = (CCNotificationObserver*) obj; if (!observer) continue; if (!strcmp(name,observer->getName())) observer->performSelector(object); }}
20120719
Forced type conversion:
The custom class mainscene inherits from the cclayer, and uses the same method as helloworld, mainscene: Scene () to directly create a scene object, and attaches the mainscene object to scene.
However, an error occurred when calling: mainscene * pscene = (mainscene *) (pdirector-> getrunningscene (); scene is forcibly converted to cclayer, operations on the so-called mainscene object members lead to memory block exceptions. This phenomenon is caused by failure in some inexplicable places. Each time it is different, the memory block detection also reports an exception.
Dangerous forced memory conversion, please remember!
20120723
It is best not to write code with dependency in the initialization sequence of global variables.
const CCSize WIN_SIZE = CCDirector::sharedDirector()->getWinSize();
At first, debugging on vs was okay. After porting it to Android, it crashed during initialization.
I checked the information because of the initialization order. (The initialization sequence is not clear. Please try again. Thank you)
PS: I found several articles on initializing the static constant order.
1. Control the initialization sequence of global variables & # pragma details
2. initialization sequence of global variables
int get_a(){ static int a = 5; return a;}int get_b(){ static int b = get_a(); return b;}
3. Review the initialization sequence in Java
4. Tips for initializing ordered Constants
20120726
Playeffect
Preloadeffect is required before the sound effect is played. Otherwise, no sound is played for the first time. All sound effects can be preloadeffect at a time. The hashmap storage sound storage path is called by Android.
The vs end can play normally without writing preloadeffect, but the android end must first play preloadeffect. Otherwise, no sound is played for the first time. This problem was not found in background music.
20120803
Argetedtouchdelegate inheritance and dynamic_cast
I want to write a sprite that can respond to touch.
The class is defined as follows:
class GemBoard : public CCSprite, CCTargetedTouchDelegate
Then, when you register the touch message
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
I hung up here, checked for one afternoon, and hung up
-Addtargeteddelegate
-Cctargetedtouchhandler: handlerwithdelegate
-Initwithdelegate
-Cctouchhandler: initwithdelegate
-Dynamic_cast <ccobject *> (pdelegate)-> retain ();
-Void ccobject: retain (void)
So far, the compiler tells me that the this pointer of ccobject is 0 and I am dizzy. It feels weird.
Cause: cctargetedtouchdelegate is private inheritance in the above write method, and the true type can be determined according to the role of dynamic_cast: (the operator can be used during execution. If downcast is secure (that is, if the base class pointer or reference actually points to a derived class Object), the operator returns a pointer that has been transformed as appropriate. If downcast is not secure, this operator returns a null pointer (that is, the base class pointer or reference does not point to a derived class object ).) The above situation is reasonable.
Today I learned two knowledge points:
1. Class B: Public A, C. In this case, a is public inheritance, C is private inheritance, and Class B: A is also private inheritance.
2. Besides public, dynamic_cast returns NULL.
So change
class GemBoard : public CCSprite, public CCTargetedTouchDelegate
It is correct. I found my c ++ infrastructure really bad.
20121101
Today is not Halloween. How has it become a fool's day !!!
Because the project is developed under VC ++ and then compiled into local code to run on Android, log debugging needs to be printed on the real machine in some places. Today, I added n more log codes to the code, that is, I did not write a sentence. I had a hard time coding the log for a day. At first I thought it was a problem with cocos2d code, is log output automatically blocked? Search for information online. Of course, nothing can be found. I am adding the log code, and then on the real machine, I can't see the log, and then continue to add the Log Code, reciprocating loop. When I got off work, my colleagues looked at me so tangled that they asked me if I had to run the program to the log code on the VC interrupt point? The result is that the program runs normally and the breakpoint does not go away! I have been adding logs to a piece of waste code! My life is wasted. I think of a divine comedy. If you are interested, you can listen to it: Wrong
Hole-DJ lubel
20121103
Cctexture2d: initwithdata
Bool cctexture2d: initwithdata (const void * data, cctexture2dpixelformat pixelformat, unsigned int pixelswide, unsigned int pixelshigh, const ccsize & contentsize)
I tried to create a texture using data for countless times and considered various issues, that is, I don't know why the texture created normally cannot be displayed. The final parameter contentsize was found. I failed to create the parameter (0, 0). At first, I thought it was the generated texture size that was returned to me after cctexture2d was created successfully. It turns out I think more ...... This parameter specifies the texture size at the beginning.