How to reset StateBasedGame?

I’m trying to restart my game when the user clicks the button if they die but it doesn’t reset it at all. Anyone know how I can fix this? Thanks ::slight_smile:

Well, some context could be useful.
We do not even know what kind of game you are talking about, do we?
Even less how you expect this button to work.

EDIT: project = the only one you presented in here yet?
However, you could start with showing some source code.

For a general answer, you need to create a state based system for your screens. Another option would be to reset all the variables by either reloading the class or manually creating a default.

Sorry :frowning: I did’t think I provide enough information, I just didn’t really know what else to write. I just changed computer so I don’t have the source right now but I could grab it.

To expand my question further… My game involves having to dodge falling skulls, while collecting golden nuggets. The game ends if the user hits any skulls and this sets their life to 0, which then brings up the game over menu (another state in my game) When my users click on the “Play again” button this causes the game to go back to the previous state(the main game). The issue is, all the skulls and nuggets are still on the screen and the player life is still 0. I need a way in which I can set the variables again and restart the game completely. I hope this helps, sorry for not being specific

Okay, so I used the gc.reinit() method and this resets the game but it’s throwing an exception which is as follows… “Only one OpenAL context may be instantiated at any one time.” This causes the sound to not run so it’s an issue with reinitialising the sound, I presume but I’m not sure how to stop that.

gc.reinit() seems to contain

AL.create();

remove it there, place it somewhere else and you will(/could) be happy.

But.
Basically, the only thing you want is to reset the health and remove the objects, right?
Wheres your difficulty to do exactly and just that?

While I check to see if anyone answers my questions I notice yours a few times so I try to answer in my opinion. I think you should have some kind of game state manager set up to switch to the menu state or whatever you name it.

Youtueber who teaches it: https://www.youtube.com/user/ForeignGuyMike

Look under his playlists for java game programming he does more to. In the dragon tale he sets one up and has a separate tutorial on it in one of the other playlists or just a video ;D

Thanks for the replies guys. It’s pretty late here so I will reply fully in the morning. I can easily set the health variable back to normal but for some reason if I try to remove the coins/skulls, they get replaced with white squares… not sure what is going on, but I’m tired, so for the moment I am using gc.reinit until I can fix this issue.

Where do you store the objects? In one list?
What do you do to remove them?

Okay so I literally opened Eclipse and within 5 minutes I solved the issue xD. I made the stupid mistake of only removing the objects if they collide with the player and had no way of removing them all. I basically went into my render method and said that if play life == 0, don’t render them. They all went away xD, oops. It’s not very pretty at the moment and I need to organise my code but at least it is working! :slight_smile: