Cocos2d-x V2.2 Windows Phone 8 return key monitoring capture

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Don't know if you use the new 2.2 engine in the game to wp8 up, these days has been on this, really in trouble, a lot of problems, so want to back or much more to share some of the problems in the process of porting Windows Phone 8.

I submitted to the windows phone app store, there is a game, not through the audit, give me the error report points out, the return key without treatment, need to give some information for game player, so I have a black face, and then Speechless, actually I also didn't want to have this problem.

In cocos2dx, provides some functions of keyBackClicked and keyMenuClicked on IOS and Android platform, to response to the back menu key and the home key, thought that this is also support the wp8 platform, but a test of no effect, even using the platform selection, such:
void HelloWorld::keyBackClicked()
{
	#if(CC_TARGET_PLATFORM==CC_PLATFORM_WP8)
	{
		//doThings();
	}
	#endif
}
Press the return key is no solution, or will be forced to close.

Because I have no contact with Windows Phone development, simply do not understand this set of development Microsoft, so I had to check API, Baidu once, visit the forum, cocos2dx forum, does someone asks this question, but no one gives the solution, online search is also a lot of native the return key monitoring. Cocos2dx this set has been very mature, not this problem is not taken into account, so only re from the solution finding method.

Later found the answer here, in their own projects, a project name of the cpp file

Indeed, not to read the cpp file, just do when transplanting, just want to hurry let it run, no more in this inside the code. In this cpp file inside, one way is to solve the return key monitor problem.
If the file is not modified, should be in the 108 row can see such a method
void FirstGame::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args)
{
    // Leave args->Handled set to false and the app will quit when user presses the back button on the phone
}

Method of the notes is very clear, as long as the args-> Handled is false, then press the return key the program will quit, of course, the default is false

For example, we want to make the game press the return key not quit the game, only can be set to true
void FirstGame::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args)
{    
     args->Handled = true;
}

Of course, this is not a game in each scene, don't press the return key to exit, so the best way is to use a single case, if the scene in game main menu, press the return key response is no response, other state
void FirstGame::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args)
{
    If (game main menu)
    {
          args->Handled = true;
          //doThings();
    }
    else
          args->Handled = false; 
}

So that you can.~
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Serena at November 28, 2013 - 5:11 PM