In my game, when the users clicks an image button, the value of a boolean changes and then the game is closed. I mean, if I want to restart the game, I click this image button, the game is closed and immediately is opened. However this doesn't happen because the value of the boolean is false and I don't know why at all.
Here is the code of the image-button:
playagain.addListener(new ClickListener()
{
@Override
public void clicked(InputEvent event, float x, float y)
{
interfaccia.rigioca();
Gdx.app.exit();
}
});
And this is the code of the MainActivity:
public class MainActivity extends Activity implements MyGdxGame.GestioneClick, Serializable
{
MainActivity activity;
boolean start;
@Override
public void onCreate(final Bundle bundle)
{
super.onCreate(bundle);
setContentView(R.layout.layout);
activity = this;
findViewById(R.id.button).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
startActivity();
}
});
}
@Override
public void onResume()
{
super.onResume();
if(start)
startActivity();
}
@Override
public void menu()
{
start=false;
}
@Override
public void rigioca()
{
start=true;
}
public void startActivity()
{
Intent intent = new Intent(MainActivity.this,AndroidLauncher.class);
intent.putExtra("MainActivity",activity);
activity.startActivity(intent);
}
}
As you can see, rigioca method is called and start sould be true. I checked ALL with logs and we can say that the value is true. Then resume method is called but start value is false! How is it possible? I also took away start=false;
in menu method, but that isn't the problem. Why is this variable false!?
Note: onDestroy and onCreate aren't called but the activity is destroyed.
currentTurn
, an array ofenemies
, and so on. Instead of completely restarting your game just setcurrentTurn = 0
and doenemies.clear()
to reset them to their original state. \$\endgroup\$