BackButtom wp8-xaml

Hey guys

I need to configure the function of the back button to be able to submit my application. I had already solved this problem in the project wp8 but now I can not solve this problem how can I use this porjecto keyBackClicked functions.


hope it will be useful for you

Yeah, can you describe your problem more clearly with some codes? And make sure you calls the function in the right thread, as the operation in Mai Dung’s links. Thanks.

What does “TestController ()” function?
But your code to work with my min “OnBackKeyPress ()” function.

// user pressed the Back Key on the phone
bool Cocos2dRenderer::OnBackKeyPress()
{
	CCScene* scene = CCDirector::sharedDirector()->getRunningScene();
	CCObject* child = scene->getChildren()->objectAtIndex(0);
	CCLayer* s = (CCLayer*)child;
	if (s)
		s->keyBackClicked();
	if (CCDirector::sharedDirector()->nScenes() > 0)
		return true;
	return false;
}

But when I am in the initial stage and I click the back button it does not close the application.

One more question is there any way to debug code in c + +? (this type of project)

I changed your function.

bool::Direct3DInterop OnBackKeyPress() 
{
std::lock_guard <std::mutex> guard(mMutex); 
std::shared_ptr<BackkeyEvent> e(new BackkeyEvent()); 
mInputEvents.push(e); 
if (cocos2d::CCDirector::sharedDirector()->nScenes() > 1) 
    return true; 
return false; //return true here to avoid the mainthread do it again 
}

so that if there is only one scene in the stack when clicking the back button to close the app.

about debug in wp8-xaml: [[http://www.cocos2d-x.org/forums/6/topics/43256?r=43280#message-43280]].
It seems that you can close the applicaton while Direct3DInterop::OnBackKeyPress() return false like the testcpp project.

How do I do here?

Joel Oliveira wrote:

I changed your function.

bool::Direct3DInterop OnBackKeyPress() 
{
std::lock_guard <std::mutex> guard(mMutex); 
std::shared_ptr<BackkeyEvent> e(new BackkeyEvent()); 
mInputEvents.push(e); 
if (cocos2d::CCDirector::sharedDirector()->nScenes() > 1) 
    return true; 
return false; //return true here to avoid the mainthread do it again 
}

so that if there is only one scene in the stack when clicking the back button to close the app.

Sorry I have not the environment to debug as I am at home now. But It can close the application normally in testcpp project while click the back button. You can debug in testcpp and find the way as it just return false in Direct3DInterop::OnBackKeyPress() and results OK in my memory. Thanks.

Hey Guys,

I’d like to offer my solution to the back button because I think all the other solutions are project specific.
I would not touch the Direct3DInterop Class but change the Cocos2dRenderer::OnBackKeyPress() as follows.

bool Cocos2dRenderer::OnBackKeyPress()
{
	CCDirector::sharedDirector()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
	return true;
}

This way It will react the exact same way as android when we overload the virtual void keyBackClicked(void) function in our layers :slight_smile:

NB Don’t forget to add setKeypadEnabled(true); in the init of your layers.

I’ll try and get this merged upstream soon :wink:

Kind Regards
Martell