How to detect only if back button is pressed?

How to detect if back button has been pressed on windows phone 7?

  • I have searched for this for ages but I can't find an answer that applies to me. I'm using cocos2d for xna and am trying to make it so when the user presses the back button on the windows phone, the application won't close I saw that on xna your supposed to use if (GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One).Buttons.Back == ButtonState.Pressed) But cocos2d doesn't have an update method, so I tried overriding the update method like this public override void update(float dt) { Debug.WriteLine("testing"); if (GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { int i = 10; Debug.WriteLine("LOL"); } base.update(dt); } But that method doesn't fire. Another thing I came acroswas the NavigationService.navigate method, but thats used in the standard silver light stuff and not for moving between c.s files in cocos2d. Can anyone tell me what I need to do? Thanks in advance

  • Answer:

    This is the correct way to detect a back button press: if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { } I'm not sure how Cocos2D works, but wherever you are doing your game logic, that is where you'd put this code. I would imagine that you have a Game class, and you should have an Update method in the game class, that calls Cocos2D update logic, I would put this there. Can you elaborate on where you put the code above?

user819640 at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.