Best Way To Restart Game In Storyboard?

Warren, see below a blank storyboard template that I have set up. Your game code (touch listeners, enterFrame listeners, game logic, functions etc) goes above all the storyboard functions. Within createScene you load all your display objects, and add any touch listeners you need (the code for which will be higher up in the lua file). Within enterScene you can start timers or add runtime listeners, and remember to cancel/remove these in willExitScene.

[lua]

module(…, package.seeall)


–LIBRARIES


local storyboard = require(“storyboard”)

local scene = storyboard.newScene()


–DISPLAY GROUPS


local localGroup = display.newGroup()


–LOCAL VARIABLES


local scene = storyboard.newScene()


–OBJECT DECLARATIONS



–GAME FUNCTIONS


local gameLoop = function ()

end


– STORYBOARD FUNCTIONS


– Called when the scene’s view does not exist:

function scene:createScene(event)

    localGroup = self.view

end

– Called BEFORE scene has moved onscreen:

function scene:willEnterScene(event)

    local group = self.view

end

– Called immediately after scene has moved onscreen:

function scene:enterScene(event)

    local group = self.view

    local ready = function()

       local previous = storyboard.getPrevious()

       if previous ~= “main” and previous then

            storyboard.removeScene(previous)

        end

    end

    timer.performWithDelay(1000, ready)

    Runtime:addEventListener(“enterFrame”,gameLoop)

end

– Called when scene is about to move offscreen:

function scene:exitScene(event)

    local group = self.view

end

– Called AFTER scene has finished moving offscreen:

function scene:didExitScene(event)

    local group = self.view

    Runtime:removeEventListener(“enterFrame”,gameLoop)

end

– Called prior to the removal of scene’s “view” (display group)

function scene:destroyScene(event)

    local group = self.view

end

– Called if/when overlay scene is displayed via storyboard.showOverlay()

function scene:overlayBegan(event)

    local group = self.view

    local overlay_scene = event.sceneName – overlay scene name

end

– Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()

function scene:overlayEnded(event)

    local group = self.view

    local overlay_scene = event.sceneName – overlay scene name

end


– END OF YOUR IMPLEMENTATION


scene:addEventListener(“createScene”, scene)

scene:addEventListener(“willEnterScene”, scene)

scene:addEventListener(“enterScene”, scene)

scene:addEventListener(“exitScene”, scene)

scene:addEventListener(“didExitScene”, scene)

scene:addEventListener(“destroyScene”, scene)

scene:addEventListener(“overlayBegan”, scene)

scene:addEventListener(“overlayEnded”, scene)


return scene

[/lua]

Hi again,

Do you use the windows or mac version of corona? I am posting the windows version of my game. I still don’t have it right though. And I know some of the coding is bad but it kind of works! :slight_smile: I’m still learning…

You pull back on the horse shoe the cowboy is holding and it is thrown to knock over the beer cans. Still need to adjust the power and all more.

Warren

http://www.watchyourbabysitter.com/throw7.zip

Is that the latest version of the code? When I run it the game is in portrait (as set in build.settings), the background scrolls away, the cans fall everywhere and when the cowboy comes on screen you can’t grab the horseshoe.

I’m running on mac but that shouldn’t make any difference to how the code runs.

That is the latest. The app is in portrait mode because the other screens that this goes to must be portrait. So I had to set the gravity to another direction and rotate the images by 90 degrees. It works for me in the simulator and device this way.

Does anyone know what function is called in a storyboard for reloadScene? I’m still trying to get the code in the right places so this method works.

Thanks