Problems and solutions encountered in the development of aircraft war games:
1. When I add a menu, I want to add a menu with background, need to add a picture sprite in the menu pmenu, the result is compiled but run in error, such as:
Checked a lot of information, debugging for a long time, the whole person will collapse.
Finally, it is found that the Ccmenu::itemfortouch function in the engine has the behavior of traversing the child nodes, but the loop does not determine whether the child node type is Ccmenuitem. the image Sprite added to the pmenu is used as a menu item, resulting in an error. The old version of the true and imperfect place, the whole people are not good ...
Decisively modify the source in the engine as long as the Ccmenuitem type is determined before using the child nodes in the traversal,
2. At the time of development, it is unavoidable to use the keyboard message to test the program function, but for a long time found that the engine did not get us out of the keyboard message. So... Decisively modify the source code.
Step one: Add virtual void processwin32keypress (UINT message, WPARAM WPARAM, LPARAM LPARAM) under public in the Cclayer class declaration {}
Step Two: Add the variable Cclayer *m_playwin32key under private under the Cceglview class declaration; Add the function void Setwin32keylayer (Cclayer *player) under public {m_ Playwin32key = PLayer;}
Step Three: Initialize Cclayer (null) in the Cceglview constructor, and the WindowProc function initially adds the IF (null! = M_playwin32key) {m_playwin32key-> Processwin32keypress (Message, WParam, LParam);}
Step four: Regenerate libcocos2d;
Step Five: Add Ccdirector::shareddirector ()->getopenglview ()->setwin32keylayer (this) in the constructor or initialization function that inherits from the subclass of the Cclayer class;
Step Six: Override the Processwin32keypress function in subclasses to handle keyboard messages;
Step Seven: Add Ccdirector::shareddirector ()->getopenglview ()->setwin32keylayer (NULL) in the function before the subclass's destructor or destructor.
So we can handle the message as we like.
3. When using the keyboard keys to control the movement of the aircraft, it is found that there is always some Dayton. In fact, there is a problem with this mechanism.
WORKAROUND: Instead of moving the aircraft while processing the message, just set the motion mode when processing the message, and in the callback refresh function, move the aircraft according to the way the aircraft is moving.
An example of aircraft war game development based on cocos2d-x-1.0.1 (top) cocos2d-x-1.0.1-based aircraft war game development Example (middle)
An example of aircraft war game development based on cocos2d-x-1.0.1 (II.)