I may be having a big misunderstanding of how best to remove and reload levels.
I am using the Composer API in conjunction with LD. In my menu system which shuffle through scenes such as titlescreen to options menu and back or from title screen to levelselect then to the game I am able to use the myLevel:removeLeve() myLevel = nil code (in the:scene destroy function) and then have it reloaded in the scene:create function. In any scene that comes from another scene I call a removeScene command in the did phase of the scene:show of the current scene. This seems to work ok and the levels seem to reload.
I assuming my problem has to do with misunderstanding how the self.view and LD work together and how to make sure when I remove an object and want to reload it how to make sure its in the scenes view.
First some info on the actual game loop. I have two levels over lapping eachother 1) the level itself (platforms, player objects) and 2) the HUD (DPAD, buttons, etc) In the Scene:Create listener I load the level first and then the HUD so that the HUD is painted in the foreground.
Where I am running into the problem: My game loop, which is located in the scene:show “did” phase, runs on a runtime listener all other listeners (collision and touch) are in the create:scene listener. In the HUD there is a game pause button this calls a composer overlay scene. In this overlay I have two buttons at the moment, a back and a restart, the back button works as expected. It’s the restart that is causing me trouble.
I have tried many ways to kill the scene and reload the level or to remove the level and reload it without killing the scene (technically I am removing 2 levels the level itself and the HUD)
Things I have tried: Having the restart listener in the overlay send a composer variable that flags inside the game loop that if this variable is true to remove the 2 levels and then run my loadLevelObjects() Function which is currently only called at the scene:create phase.
ie:
function scene:create( event )
application.LevelDirectorSettings.viewGroup = self.view
loadLevelObjects()
where loadLevelObjects looks like this:
function loadLevelObjects()
myLevel = LD:loadLevel(‘LevelNov3’)
controlPanel = LD:loadLevel(‘controlPanelLev’)
player = myLevel:getLayerObject(“Player”,“Player”).view
slideOffSensor = controlPanel:getLayerObject(“Controls”, “slideOff”).view
slideOffSensor.isHitTestable = true
and many more objects …
In case it’s a question of scope (could this be the problem?) the loadLevelObjects functions is located after the scene:create and before the scene:show in the code.
So in my game loop I may have some sort of check such as:
if(restart) then
myLevel:removeLevel()
controlPanel:removeLevel()
myLevel = nil
controlPanel = nil
loadLevelOnjects()
restart = false
end
But this did not work. Whatever I try I end up with the same solution which seems to be the white screen left from removing the level. Actually if I remove only one of the levels they both seem to disappear.
The other tactic I have tried is killing the scene itself by using a intermediate scene from the overlay. So you click restart in the pause overlay and it goes to another scene called levelLoader in the scene:create it kills the game scene using removeScene and in the the games scene:destroy function I remove the 2 levels and make them nil. Then in the scene:show did phase of levelLoader I call gotoScene on the game scene and hope this brings me back to the game. Ideally, in the game scene, this would start the create:scene and load the levels as it does in the first place. I have also tried many variants of these two techniques to no avail.
SO now that my essay is done, maybe you can help me figure out what I am doing wrong? I want a button in my game pause overlay to reload a level. (I don’t just want to reset variables because I have objects that disappear on collision that I want to return and do not want to load by hand - therefore I want the whole level to reload fresh.)
I think I must not completely understand the scene view and how LD interacts because I was having a similar problem trying to remove and reload a layer object in the middle of a touch listener. Ie. I create a layerObject using the createLayerObject funtion I eventually call to remove the Object and then I try to create it again and it does not appear to work.
is my problem something to do with understanding the utility methods (copied from your documentation):
LD:removeLevel()
and
LD:cleanUP?
LD is the instance of the LD_loader and if I use the LD:removeLevel() as your documentation shows and I have two levels loaded how can I determine which level will be removed? should the LD not be a level object?
Ideally I want to remove only the myLevel LD Level and leave the HUD (controlPanel) on screen at all times. When I remove one it seems to remove both.
Any help would be fantastic, you have been very helpful in the past and I appreciate that. If you want more clarification or need more info let me know.