[Solved] Windows Phone 8 framework. Back button handling

Hi all!
I’m trying to create first cocos2d-x application for WP8 and use 0.13 wp8 package. Can someone tell me, how to handle Back button pressing? It’s very important for me at this time. Without this opportunity i can’t publish my app in marketplace.

Override *keyBackClicked()* on your layers

Lance Gray wrote:

Override *keyBackClicked()* on your layers

unfortunately that’s not works.

Has anyone solution of this problem?

you can read at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247550(v=vs.105).aspx.

you can create class ref handle code detect pressed Back button, and use that in CCLayer.

Natokan Sonkugo wrote:

you can read at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247550(v=vs.105).aspx.
>
you can create class ref handle code detect pressed Back button, and use that in CCLayer.

Natokan Sonkugo, thank you!

I solved this task.
To add backbutton handling i need make next steps:

  1. In CCApplication_win8_metro.cpp before definition of class CCFrameworkView in using block add string using namespace Windows::phone::UI::Input;
  2. Add public method to class CCFrameworkView void OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args);
  3. In method void CCFrameworkView::OnActivated(
    In CoreApplicationView^ applicationView,
    In IActivatedEventArgs^ args
    )
    add string
    HardwareButtons::BackPressed += ref new EventHandler<BackPressedEventArgs^>(this, &CCFrameworkView::OnBackButtonPressed);
  4. Define method my method OnBackButtonPressed.

Mik Mad wrote:

Natokan Sonkugo wrote:
> you can read at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247550(v=vs.105).aspx.
>
> you can create class ref handle code detect pressed Back button, and use that in CCLayer.
>
Natokan Sonkugo, thank you!
>
I solved this task.
To add backbutton handling i need make next steps:

  1. In CCApplication_win8_metro.cpp before definition of class CCFrameworkView in using block add string using namespace Windows::phone::UI::Input;
  2. Add public method to class CCFrameworkView void OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args);
  3. In method void CCFrameworkView::OnActivated(
    In CoreApplicationView^ applicationView,
    In IActivatedEventArgs^ args
    )
    add string
    HardwareButtons::BackPressed += ref new EventHandler<BackPressedEventArgs^>(this, &CCFrameworkView::OnBackButtonPressed);
  4. Define method my method OnBackButtonPressed.

Thanks, I try your method, it works.
One more question: How to trigger a method in the MainScene or the AppDelegate for further processing.

Eric Hung, hi!
In my application, i use back button to go to previos scene.
I think that you can realize that up to, but you should first examine the application architecture.

Mik Mad wrote:

Eric Hung, hi!
In my application, i use back button to go to previos scene.
I think that you can realize that up to, but you should first examine the application architecture.

I get the back key event in CCApplication_win8_metro, but if I try to inject it to CCDirector it crashes:

CCDirector::sharedDirector()->getKeypadDispatcher()->dispatchKeypadMSG( ccKeypadMSGType::kTypeBackClicked );

Any idea?

Thanks,
Marcelo

You better use the backkey delegate.

Have a look at the news of Cocos2d-x for wp8 v2.0 preview. There is solution there.

Hey Guys…
im a newbie testing out cocos2d x…

so I’m now stuck with the back button…
I checked out the solution on the news of Cocos2d-x for wp8 v2.0 preview
I updated the CCApplication ####.cpp and CCApplication ###.h but now my question is how do I use it in my scene.

I got the helloworld example up and running with the backbutton implementation. how would I check on helloworldscene to see if the back button as been pressed.?
now from what I understood if I wanted my app to close all I have to do is return false. if I wanted it not to close, for instance return to a previous scene I turn true and replace scene with whatever previous scene I want…

Hey Mik,

I am having a little trouble understanding your steps in your post. Can you please help me out, I am stuck at the same point. I want to navigate to a specific Scene on backButtonPress. Help out.
thanks.

Mik Mad wrote:

Natokan Sonkugo wrote:
> you can read at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj247550(v=vs.105).aspx.
>
> you can create class ref handle code detect pressed Back button, and use that in CCLayer.
>
Natokan Sonkugo, thank you!
>
I solved this task.
To add backbutton handling i need make next steps:

  1. In CCApplication_win8_metro.cpp before definition of class CCFrameworkView in using block add string using namespace Windows::phone::UI::Input;
  2. Add public method to class CCFrameworkView void OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args);
  3. In method void CCFrameworkView::OnActivated(
    In CoreApplicationView^ applicationView,
    In IActivatedEventArgs^ args
    )
    add string
    HardwareButtons::BackPressed += ref new EventHandler<BackPressedEventArgs^>(this, &CCFrameworkView::OnBackButtonPressed);
  4. Define method my method OnBackButtonPressed.

Specifically, what should I write in onBackButtonPressed event handler to go to the previous scene.
My application has only three scenes:

Menu , Scan and Result.
I want that on Scan scene the back button should go to Menu, on Result back button should go to Scan and on Menu the back button should terminate the application.

How can I accomplish this ?

Hi all,
i’m using cocos2d-x v3.2 to make my first WP 8 Game. But i don’t know how to handling my back button to replaceScene or end game.
Help me solve it, pls
Thanks,