1
\$\begingroup\$

i have set main class like this:

public class MyClass extends Game {
    MenuClass menuClass;
    ActionGame actionGame;


@Override
public void create() {
         menuClass = new MenuClass(this);
         actionGame = new ActionGame(this);
         setScreen(actionGame);
    }
}

and method of ActionGame class like this:

....
@Override
public void pause() {
    game.setScreen(game.menuClass);
}

@Override
public void resume() {
    this.show();
    this.render(Gdx.graphics.getDeltaTime());
}
....

and method of menuClass.java like this, when touch Play button:

....
@Override
public void resume() {
    game.actionGame.resume();
}
....

When i touch play button i wish that actionGame class return in action render, but the render don't start. I have try with setScreen, but this restart my screen, this not good. Help

Thanks

\$\endgroup\$
3
  • \$\begingroup\$ Remember, that pause is called, when your game looses focus, resume gets called when you return to the game. So seting the screen to menu on pause and setting it back to actiongame on resume does not seem to make sence. Instead you should have a method pauseGame, which stops the logic from being updated. \$\endgroup\$
    – Robert P
    Oct 30, 2015 at 9:52
  • \$\begingroup\$ in essence it is what I did back then , right? if the logic I have to do it then what is the point to use the screen ? \$\endgroup\$
    – Dev4Ever
    Oct 30, 2015 at 10:03
  • \$\begingroup\$ I guess it is to much to write it as a comment, i'll add an answer and i hope, that i did not missunderstand your question... \$\endgroup\$
    – Robert P
    Oct 30, 2015 at 12:56

1 Answer 1

1
\$\begingroup\$

The method pause is called, when your app looses focus. On Android this happens, if you press the home button or a call is incoming. When you return to the app, resume gets called.
So if you switch from GameScreen to MenuScreen inside the pause method, and switch from MenuScreen to Gamescreen inside the resum, the MenuScreen will never show, as it is active only when your app is in background.
What you might want to do is to switch to MenuScreen on pause, but on resume don't switch back. Instead you should wait till the user presses a button Continue and then go back to the GameScreen.
Also, you should not call pause or resume yourself, those are methods called by the framework in specific situations.

EDIT:
I also noticed, that you call show method inside the resume method. The method show is another method, used by the framework. It is usually called, when you switch Screen (setScreen in the Game class calls hide for the current Screnn and show for the new Screen).
Also the render method should generally not be called by you. The Game class automatically calls the render of the current Screen in it's own render. So if you set the right Screen, the right render method will be called.

EDIT 2:
A possible approach for you might be the following:
Inside the pause method, save the game data, as it is possible, that the user closes the app (or Dalvik decides to close it cuase the system needs the ressources). You can also call setScreen(menuScreen) here. This call will result in a call to actionGame.hide(), where you might release some of the ressources used by the GameScreen. Then it will call menuScreen.show() where you might load ressources needed by the MenuScreen.
When you return to the app menuScreen.resume() will be called. You don't need to do anything here. Instead you should waint, till the menu button Continue is pressed. Here you can load the saved data and the setScreen(gameScreen).

\$\endgroup\$

You must log in to answer this question.

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