SCENE LOGIC

Hi there,

to be true, i don’t get the whole SCENE Concept.
I just get errors like:

Runtime error
/Applications/CoronaSDK/testgame/main.lua:2: attempt to index global ‘director’ (a nil value)
stac

Once i tested with that director.lua it loaded another .lua but looked as he would mix my first lua with the second.

can’t i just load another scene… my old comes completely closed/destroyed and the one i call opens up fresh and new?

thx
chris

[import]uid: 4795 topic_id: 13423 reply_id: 313423[/import]

even if you use director class for changing scenes, you need to manually remove everything from a scene prior changing it to another [import]uid: 16142 topic_id: 13423 reply_id: 49321[/import]

oh wohhhh.

how much easier it could be when I just call another .lua
and all variables and objects are released and the new .lua
just start from the beginning… a few global variables and the whole
thing would be just great.

that unnecessary complicated from my point of view.
but what should i do… can just change my whole code

thanks for your answer
greets
chris
[import]uid: 4795 topic_id: 13423 reply_id: 49322[/import]

I don’t think you have to remove every object in current scene before loading new scene.
in director 1.2 I can see a cleanGroups() which will loop through all the display objects in group and will remove them.

see the code used for that
[lua]local function cleanGroups ( curGroup, level )
if curGroup.numChildren then
while curGroup.numChildren > 0 do
cleanGroups ( curGroup[curGroup.numChildren], level+1 )
end
if level > 0 then
curGroup:removeSelf()
end
else
curGroup:removeSelf()
curGroup = nil
return true
end
end[/lua]
In director 1.3 the release note says that

Function cleanGroups() removed
There is no need to keep this function because Ansca changed the removeSelf() method to be recursive, so now the scene groups are cleaned only with the removeSelf().

But in order for director class to remove the display objects in current scene you should make sure that all objects in the current scene are added to a local display group which is passed as part of director class.

NOTE: What I notice is, if you are loading a new scene from your main.lua file you have to manually remove all the display objects as main.lua is not loaded from a local group returned as part or Director class.
*edit
To know whether your display objects are properly removed the simplest way is to try renaming it when the new scene is loaded. If its still being used it will throw an error message. [import]uid: 71210 topic_id: 13423 reply_id: 49361[/import]