OnPause and OnResume

  ... discussions about development with the GLES2 branch of AndEngine.

OnPause and OnResume

Postby LessisMooreProductions » Fri May 31, 2013 9:27 pm

Hi,

I can't seem to find decent examples on how to pause and resume in-game. This is what I want to do :

during play, there are 3 enemies on the scene. All three at a different X and Y coord. When I press the back button, the game pauses. When I open the game back up, I want to resume, and find the 3 enemies at the same place. The code I could find in the examples all reload the textures, and all recreate a scene from scratch, which of course causes the game to restart.

Any pointers on how to accomplish this?

thanks a million
LessisMooreProductions
 
Posts: 6
Joined: Thu May 02, 2013 7:48 pm

Re: OnPause and OnResume

Postby RealMayo » Fri May 31, 2013 10:00 pm

Pause and Resume are not meant to work with the back button. They are meant to work with the Home button and the Power button, meaning that your game remains as a running process on your phone. Furthermore, pause and resume work automatically. You really shouldn't have to add any code in those methods. What you definitely must do though is add this to your manifest file within the tags of your main activity...
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|mcc|mnc
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
User avatar
RealMayo
 
Posts: 1690
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL

Re: OnPause and OnResume

Postby ChrisB2404 » Sat Jun 01, 2013 12:27 pm

Like RealMayo said using onPause and onResume won't be your best options. I handle the back button by listening for its press and consuming the touch even so Android doesn't close my game. From this you can create your own "pause" event. I would suggest calling this pause event on your onPause event as well
User avatar
ChrisB2404
 
Posts: 80
Joined: Sat Feb 04, 2012 10:39 pm
Location: Dundee

Re: OnPause and OnResume

Postby RealMayo » Sat Jun 01, 2013 3:52 pm

If you want to Pause once the user clicks the Back button, then all you have to do is attach a MenuScene to your main Scene. The builtin AndEngine MenuScene is a very smart method that automatically pauses your game once its attached to your main Scene. And then it automatically unpauses your game once you click any of the buttons within the MenuScene. The MenuScene is where I have my "Restart", "Resume", "GoBack" buttons.
User avatar
RealMayo
 
Posts: 1690
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL

Re: OnPause and OnResume

Postby LessisMooreProductions » Sat Jun 01, 2013 6:31 pm

Thanks alot! I'll take a look at it
LessisMooreProductions
 
Posts: 6
Joined: Thu May 02, 2013 7:48 pm

Re: OnPause and OnResume

Postby Sergio » Thu Aug 01, 2013 3:57 pm

RealMayo wrote:The builtin AndEngine MenuScene is a very smart method that automatically pauses your game once its attached to your main Scene.


When I set the MenuScene as a child scene of the main Scene it's not paused at all, I can keep playing with the pause menu in front of it. I also tried just attaching it as a child but didn't work either.

Is there anything else to do for this to work properly?
ImageImage
Sergio
 
Posts: 10
Joined: Wed Jul 10, 2013 6:12 pm

Re: OnPause and OnResume

Postby RealMayo » Thu Aug 01, 2013 3:59 pm

Look at the AndEngine Examples for how to implement it.
User avatar
RealMayo
 
Posts: 1690
Joined: Sat Sep 03, 2011 9:25 pm
Location: Chicago, IL


Return to GLES2

Who is online

Users browsing this forum: Belllivelove and 37 guests