I have read that some developers code individual Lua files for each level. I would like to go the route of having a level config file. The issue I am coming across is that I cannot seem to insert the objects I create in the config file into localGroup in my main file. Unfortunately, I get a generic Director error message. It is probably something obvious, but I am too close to the tree to see the forest.
The following lines are in my main file…
local levelConfig = require("levelConfig")
local generateLevel = levelConfig.generateLevel
--
--
--
generateLevel({ level = vlevel })
…and the following is the code in the config file.
function generateLevel( params )
local level = params.level
if params then
if level == 1 then
local wall10 = display.newImage("graphics/wall.png", 500, 450)
physics.addBody(wall10, "static", {density=1.0, friction=1.0, bounce=0.5})
wall10.myName="wall"
localGroup:insert(wall10)
elseif level == 2 then
print ("Level2 = " .. level .. ".")
elseif level == 3 then
print ("Level3 = " .. level .. ".")
end
end
end
The wall is actually created on the screen…it just isn’t in the right display group. I have tried “localGroup:insert(wall10)” in both files at different times with the same (bad) results. Is there something I need to do that can make the groups visible across Lua files or am I on the wrong rack completely??? (Is that why folks default to individual files for each level?)
Thanks,
David [import]uid: 71572 topic_id: 13065 reply_id: 313065[/import]
I have added that piece but still am having issues.