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

1
2
3
4
5
module(..., package.seeall)
 
-- Main function - MUST return a display.newGroup()
function new()
        local localGroup = display.newGroup()

@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.

Thanks for the tips, are there any resources/samples to implement initVars() ?

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
...
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

understood, thanks for the sample.

..Im a Lua newb, but catching on quick!

Lua isn't a hard programming language to learn. Soon you will master it.

views:1697 update:2011/10/13 9:25:17
corona forums © 2003-2011