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
}
/////////////////////////////////////////////////////////////////////////
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
}
/////////////////////////////////////////////////////////////////////////
Thanks.
ReplyDelete