Director Help?

The problem im having is when GameOver happens and the button apears for new screen the process (game) still runs and when I click new game (new scene to same game) it doubles up on top of the old game lol… is there a simple function to force a restart/reload using this method??

thanks in advance for your time…

top of main.lua [lua]module(…, package.seeall)

– Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()[/lua]

game code here (not posted)

game over…

[lua]function gameOver()
local overSplash = display.newImage( “game_over.png”, true )
overSplash.alpha = 0
overSplash.xScale = 1.5; overSplash.yScale = 1.5
local showGameOver = transition.to( overSplash, { alpha=1.0, xScale=1.0, yScale=1.0, time=500 } )

local bt01 = display.newImage(“bt_button.png”)
local function bt01t ( event )
if event.phase == “ended” then
director:changeScene(“game”,“button”)
end
end
bt01:addEventListener(“touch”,bt01t)
bt01.x = 100
bt01.y = 300
localGroup:insert(bt01)

cueball:removeEventListener( “touch”, cueShot )
end

cueball:addEventListener( “touch”, cueShot )

return localGroup
end [/lua]

[import]uid: 13743 topic_id: 5525 reply_id: 305525[/import]

@neptune1

I don’t think you really need to reload the same file. At the game that I’m building, I have a function called initVars() where I have all the values and positions set. When I want to restart the game, I simply call it. But if you want to reload again, the best thing to do is go to a new file “gameover.lua” or something like that and go back to your game file from there.

Now talking about your code, take a look at the exemple on how to use the main.lua file.

I have on my game a pause() function where I remove all the listeners and stop transitions and timers. When I want to go back to the game, the same function recreates all of this with the state that they were. To store the state, I have a few variables just for it.

One more thing, never forget to insert your graphics into the localGroups or they will remains at the screen. [import]uid: 8556 topic_id: 5525 reply_id: 18786[/import]

Thanks for the tips, are there any resources/samples to implement initVars() ? [import]uid: 13743 topic_id: 5525 reply_id: 18891[/import]

I can’t send you my code because is part of my game, but try something like this:

[code]

local player = display.newImage(“player.png”)
localGroup:insert(player)
local playerLife

local enemy1 = display.newImage(“enemy1.png”)
localGroup:insert(enemy1)
local enemy1life

local enemy2 = display.newImage(“enemy2.png”)
localGroup:insert(enemy2)
local enemy2life

local function initVars ()

player.x = 300
player.y = 100
playerLife = 1000

enemy1.x = 200
enemy1.y = 300
enemy1life = 100

enemy2.x = 400
enemy2.y = 300
enemy2life = 100

end

function new ()

initVars()

return localGroup

end
[/code] [import]uid: 8556 topic_id: 5525 reply_id: 18901[/import]

understood, thanks for the sample.

…Im a Lua newb, but catching on quick! [import]uid: 13743 topic_id: 5525 reply_id: 18984[/import]

Lua isn’t a hard programming language to learn. Soon you will master it. [import]uid: 8556 topic_id: 5525 reply_id: 18994[/import]