I'm making an arcade game where when you lose you press a key to go back to the menu, when you go back to the "game" state it doesn't re-load it again but continues from where its left of
How can I fix that?
Last edited by NickRock on Sat Dec 12, 2015 8:43 am, edited 2 times in total.
You'll need a way to initialize the game state externally, and call it when entering your game (and maybe in other places like after game over) rather than when switching states.
Or have a flag that says whether it needs initialization on state entry, and set it on game load and on game over.
function game:enter()
self.level = Levels.load("level-01.map")
self.player = Player(self.level.spawnPoint)
self.score = 0
...
end
There is also a function that you can use when you need to do stuff only once before entering the state: state:init(). For example, you could load the map in state:init() and just reset everything in state:enter() to avoid reading in the level every time:
function game:init() -- only called once
self.level = Levels.load("level-01.map")
end
function game:enter() -- called every time the state is entered
self.level:reset()
self.player = Player(self.level.spawnPoint)
self.score = 0
...
end
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.
I made a simple saving library for my game and it seems like it doesn't load the new highscore when I call the game:init() function
If you guys could help me find where the problem is that would be great.