4
\$\begingroup\$

I've found that after resuming my game the whole engine is reloaded and application is reinitialized. I want to save engine state and in "onResume," resume the game process from where it left off.

I've tried to save the engine (mEngine) and then after resume the game in "onLoadEngine" return saved engine. I think it is a bad solution and it doesn't work anyway.

What is the best solution for resuming my game (after the power key was pressed, for example) in AndEngine ?

\$\endgroup\$
2
  • \$\begingroup\$ You may want to ask on their forums as well: andengine.org/forums \$\endgroup\$
    – House
    Jan 26, 2012 at 17:37
  • \$\begingroup\$ I've already asked there \$\endgroup\$
    – dilix
    Jan 26, 2012 at 18:02

2 Answers 2

4
\$\begingroup\$

Since the game state is going to be specific to your game, there isn't built in functionality for this in the engine. One solution would be to write the state information you want to keep to an XML file. Likely you'd want to load this saved state in your onStart() function. But really that's up to you and how you want your game to behave.

There's a blog post about the flow between states, and when to save and load states: http://www.andengine.org/forums/post25660.html#p25660

And information on how to read/write a file: http://www.anddev.org/write_to_and_read_from_a_file-t3173.html

\$\endgroup\$
4
  • \$\begingroup\$ Ok, thx, i know about this solution, but for my game it's rather difficult now (the game is already released without this functionality ("Draw and ride")). I've tried to save the Scene in local var tempScene, everything is ok and scene is loaded... but there is no handlers, modifiers etc =) \$\endgroup\$
    – dilix
    Jan 26, 2012 at 18:16
  • \$\begingroup\$ What difference between pause on "Home button" and pause on "power button" with turning off the screen ? "Home button" pause is implemented in sample provided by amb \$\endgroup\$
    – dilix
    Jan 26, 2012 at 18:18
  • \$\begingroup\$ I'm not sure what the difference is between home and power pauses, sorry. From my understanding, there are differences between pausing and locking. Likely the device is getting locked when the power button is pressed. As far as changes after the game has been released, you'll have to update either way, so I guess you need to decide if the difficulty of adding this is worth it to you and the hassle of updating for your customers. \$\endgroup\$
    – House
    Jan 26, 2012 at 18:36
  • \$\begingroup\$ "differences between pausing and locking" - i think it is the right way - and maybe OS can kill the procces after go to sleep and AndEngine decide that simpliest way to avoid it is to rebuild the whole app, thank you, i will think about it \$\endgroup\$
    – dilix
    Jan 26, 2012 at 18:55
0
\$\begingroup\$

This tutorial will help:
https://jimmaru.wordpress.com/2011/09/28/andengine-simple-android-game-tutorial/

\$\endgroup\$
1
  • \$\begingroup\$ It is not really what i want - i've downloaded this sample and if i press power button the whole scene is rebuilt. When you press home button and then return to the game everything is ok, but after power button game is reset. \$\endgroup\$
    – dilix
    Jan 26, 2012 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .