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.
 

Tuesday 20 May 2014

Back button handling in cocos2d-x 3.0 with windows phone

It is very easy to get back button callback in your *.cpp.
There is some simple steps to solve the issue.
1. first create a class which provide callback in your *.cpp
/*///////////////////////////////////////////////////////////////////////////////////////////////////////////
That cpp provide call back to your *.cpp just inherit that
/////////////////////////////////////////////////////////////////////////////////////////////*/
namespace PhoneDirect3DXamlAppComponent
{
class backcall//,public cocos2d::CCTouchDelegate,public CCKeypadDelegate

public:

virtual  void backCalled();
static backcall* getInstance();
backcall();
~backcall();
static backcall* myptr; 
};
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "backcall.h"
using namespace PhoneDirect3DXamlAppComponent;
 void backcall::backCalled()
 {
 }
 backcall* backcall::myptr=NULL; 
backcall* backcall::getInstance()
{
return myptr;
}

backcall::backcall()
{


myptr=this;


}
backcall::~backcall()
{
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
2. then open  yourDrive\cocos2d-x-3.0\cocos\2d\platform\wp8-xaml\cpp\Cocos2dRenderer.cpp
3. search
void Cocos2dRenderer::OnBackKeyPress()
{
    // handle the backkey in your app here.
    // call Cocos2dEvent::TerminateApp if it is time to exit your app.
    // ie. the user is on your first page and wishes to exit your app.
 //   m_delegate->Invoke(Cocos2dEvent::TerminateApp); comment that line 
//and setcallback to yor *.cpp
if(backcall::getInstance())
{
backcall::getInstance()->backCalled();
}
}


for example
#include "backcall.h"
using namespace PhoneDirect3DXamlAppComponent;
class arpitLayer ,public Layer . public  backcall
{
virtual  void backCalled();
}
in cpp
void arpitLayer :: backCalled()
{
//Now you are happy to manage your back code here

}


/////////////////////////////////////////////////////////////////////////