问题
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?
回答1:
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/
回答2:
You should read this article slowly and carefully.
The source explains:
For Composer to “manage” your scene and the display objects within, all of these objects must be inserted into the scene’s view display group or a child display group of it.
The group is referenced in your code by the line at the very top of the scene:show
function:
local sceneGroup = self.view
You must add all display objects into this group, for example your local replay should be:
local replay = display.newImage('star1.png', 100, 300)
sceneGroup:insert( replay )
Once above design is followed you can start utilising the other features of the composer as you request.
来源:https://stackoverflow.com/questions/24785349/reloading-a-game-with-corona-sdk