Wednesday 6 January 2016

Some remember trics for cocos2d-x

Hello All,

We all use Cocos2d-x for our game development and some time halt because of crash and memory problems and that Issues increase our production time. So we need to avoid some silly mistakes to decrease our game production time .


  1.  Please Not write lots of line code in single class. If you do that it decrease readability of code and in game programming we always recheck our whole code of class for changing of small logic. 
  2.  Cocos2d-x is cross platform, which is power of that great game tool but some time we need to bifurcate our code logic according to platform requirement so please Define your own #define for platform tag it helps you to access your code and increase your power to bind native logic in your game.    
  3. Please please make sure your node inherited class must be added to auto release pool.                  =  MyNodeClass * m_myNodeClass= new MyNodeClass();                                       m_myNodeClass->autorelease(); =
4.  Scene is responsible to draw your sprite and images on screen and it support layering to draw. Some time we confuse about our drawing so please remember the draw rules.
   If you add child one by one to same parent then which object added first it on lower z-order and which added next to it its on upper z-order. You cane understand it from logic of list.
  That is fine about layering but when we add 100 objects on same parent one by one and after that if we assign localZorder to lowest object it show on top of all .
  Please do not add same object again addchild it is cause of crash.
 {
Node * tamp = Node::create();
parent->addChild(tamp); 
parent->addChild(tamp); 
 }
5. And the Most important thing is that be aware about callbacks and use proper callFunc for it. I prefer please use C++ 11 "bind" for you callBack.