Stuck with level design...

Hi

I began to design my game without composer first, structure was like this:

Main.lua: The whole game (touch, collision, enter frame listeners)

level.lua: All the levels (bitmaps etc.) in functions called by main.lua (like shown here)

Now I moved to composer:

Main.lua: goto startmenu.lua

startmenu.lua: choose exit, resume, play (goto play scene), etc.

play.lua: now the whole game (previous Main.lua)

level.lua: All the levels, called by play.lua

Now the problem is, that when going back from play scene to startmenu scene, the bitmaps of level.lua stay on top of startmenu, because they are not inserted into the scene’s view group of play scene. But I can’t insert them, because they are in a other file than play scene (error message). 

How can this be constructed?

Thanks for your help!

Regards

Olivier

You will need to pass the scene’s view group to your functions in your level files so you can insert them.

Rob

Thanks Rob! This sounds good, but how do I do this? Do you have a little examlpe? Sorry, I’m still a beginner…
Best regards
Olivier

I have no idea how your code is structured.

But assuming you’re following a model like:

–some .lua file

local M = {}

function M.someFunction (someParameters)

    – do stuff

    return someObject

end

return M

Then you would do:

–some .lua file

local M = {}

function M.someFunction (someParameters, group)

    – do stuff

    group:insert(someObject)

    return someObject

end

return M

Hi Thanks for your hint. But I’m having problems… :huh:

Here is some code. Scene1.lua looks like this (only the beginning and end is shown):

local sceneName = ... local composer = require( "composer" ) local scene = composer.newScene( sceneName ) function scene:create( event )     local group = self.view     Setup() end ... (here are the other scene phase functions). function Setup()    ground = display.newImage( "planet.png" )    ground.x = 600; ground.y = 1742    physics.addBody( ground, "static", { friction=1, bounce=0.6 } )    ground.myName="Moon"    scene.view:insert(ground) leveli = require("scripts.levels") leveli.level1 end

Then there is levels.lua:

local M = {}; function level1(group)         local image\_name = "level1.png"         local image\_outline = graphics.newOutline( 6, image\_name )         lv1bg = display.newImageRect( image\_name,1200,500 )         physics.addBody( lv1bg, { outline=image\_outline } )         group:insert(lv1bg)         return lv1bg end M.level1 = level1 return M;

But I get a error, that group:insert in levels.lua wants to index local group, which is nil…

Oh man… can someone be to old to understand object oriented programming?

Thanks for your help!

Olivier

I’m not too old :D  Finally got it. First insert everything in lets say displgroup: displgroup:insert(ground), Then you have to call all the functions with this:  leveli.level1(displgroup). Then insert the displgroup in the scene.view:  scene.view:insert(displgroup)

It only takes a little bit longer. ^_^  Thanks Rob, again!

You will need to pass the scene’s view group to your functions in your level files so you can insert them.

Rob

Thanks Rob! This sounds good, but how do I do this? Do you have a little examlpe? Sorry, I’m still a beginner…
Best regards
Olivier

I have no idea how your code is structured.

But assuming you’re following a model like:

–some .lua file

local M = {}

function M.someFunction (someParameters)

    – do stuff

    return someObject

end

return M

Then you would do:

–some .lua file

local M = {}

function M.someFunction (someParameters, group)

    – do stuff

    group:insert(someObject)

    return someObject

end

return M

Hi Thanks for your hint. But I’m having problems… :huh:

Here is some code. Scene1.lua looks like this (only the beginning and end is shown):

local sceneName = ... local composer = require( "composer" ) local scene = composer.newScene( sceneName ) function scene:create( event )     local group = self.view     Setup() end ... (here are the other scene phase functions). function Setup()    ground = display.newImage( "planet.png" )    ground.x = 600; ground.y = 1742    physics.addBody( ground, "static", { friction=1, bounce=0.6 } )    ground.myName="Moon"    scene.view:insert(ground) leveli = require("scripts.levels") leveli.level1 end

Then there is levels.lua:

local M = {}; function level1(group)         local image\_name = "level1.png"         local image\_outline = graphics.newOutline( 6, image\_name )         lv1bg = display.newImageRect( image\_name,1200,500 )         physics.addBody( lv1bg, { outline=image\_outline } )         group:insert(lv1bg)         return lv1bg end M.level1 = level1 return M;

But I get a error, that group:insert in levels.lua wants to index local group, which is nil…

Oh man… can someone be to old to understand object oriented programming?

Thanks for your help!

Olivier

I’m not too old :D  Finally got it. First insert everything in lets say displgroup: displgroup:insert(ground), Then you have to call all the functions with this:  leveli.level1(displgroup). Then insert the displgroup in the scene.view:  scene.view:insert(displgroup)

It only takes a little bit longer. ^_^  Thanks Rob, again!