I am creating my first iPhone game and cannot figure out how to reload my game.
I am using coronaSDK and have tried to use their composer API. When the player dies a button with "play again" appears and when he touches it I direct him to a scene called "reload.lua" with composer.gotoScene("reload")
.
In this scene I have the following code:
function scene:show(event)
local sceneGroup = self.view
local phase = event.phase
if (phase == "will") then
elseif (phase == "did") then
local replay = display.newImage('star1.png', 100, 300)
composer.removeScene("level1")
composer.gotoScene("level1")
end
end
However, this only adds level1
on top of the existing one and does not remove the one that has been used. Any ideas on how I could successfully remove level1
or reload my game?
While this is based on Composer's older brother Storyboard, the concepts still apply to Composer. It explains the various issues with trying to reload scenes, recommendations on how to manage it:
http://coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/
You should read this article slowly and carefully.
The source explains:
The group is referenced in your code by the line at the very top of the
scene:show
function:You must add all display objects into this group, for example your local replay should be:
Once above design is followed you can start utilising the other features of the composer as you request.