The storyboarding API gives us a clean interface to create, enter, exit, and ultimately destroy scenes. It allows the game to float between scenes easily which is how we transition between cut scenes, the gameplay levels, pause screen, main menu, etc. However, in each of these files we have to be more careful about the things we declare (and initilize) globally.
e.g. (at the top of the file)
local player = playerManager.addPlayer()
This is appears to be called once the first time the file is loaded, and then never again. So when the player died and went to start again, the scene:createScene for the first level would be called with a player object that was nil.
The solution was to declare the player variable globally (e..g local player = nil), and then in the create scene function, initialize it. This way, the second time through the scene (in the case of a restart), the player object is still initialized.
The second issue I tracked was why the player health bar wasn't showing up correctly in all the levels. John did some great work to encapsulate our player behavior into a player object that persists through the levels. This player object holds the players health. This was conflicting a little with the creation (and deminishing) of the player health bar. So I encapsulated the health bar inside the player object. Then, for each level that has the player object support in it, all we have to do is call a takeHit method which will apply the damage and update the bar.
Sometimes it feels like we have an insurmountable amount of work left but we keep chipping away and the product keeps getting better! Up next for me is going to be testing and trying to integrate LunaTest into our project.
No comments:
Post a Comment