This one should be simple for people here to answer, and I know that I should already know this…but…
I’m trying to modularise my code and I need some clarification one one or two things before I really start.
I have a levelSetup.lua module file as follows:
[lua]local M = {}
local _W = display.contentWidth
local _H = display.contentHeight
local function addBorders()
local ground = display.newRect(0,0,_W,20)
ground.x = _W * 0.5; ground.y = _H - (ground.height * 0.5)
ground:setFillColor(0, 0, 0)
local ceiling = display.newRect(0,0,_W,20);
ceiling.x = _W * 0.5; ceiling.y = 0 - (ceiling.height * 0.5)
ceiling:setFillColor(0, 0, 0)
local leftWall = display.newRect(0,0,10,_H)
leftWall.x = 0 - (leftWall.width * 0.5); leftWall.y = _H * 0.5
leftWall:setFillColor(0, 0, 0)
local rightWall = display.newRect(0,0,10,_H)
rightWall.x = _W + (rightWall.width * 0.5); rightWall.y = _H * 0.5
rightWall:setFillColor(0, 0, 0)
end
M.addBorders = addBorders
return M[/lua]
When I call levelSetup.addBackground() from my level1.lua, it returns the four display objects (ground, ceiling, leftWall, rightWall) correctly. My questions are:
_1. When these objects are created and passed to level1.lua, are they created as local display objects there?
-
Do I have to (or can I) assign each object to a local variable name somehow so that I can the manipulate each later on?
-
I have a local display group named mainGroup in Level1.lua and when the objects are returned from the levelSetup.addBackground() call, I want to add the four objects to the mainGroup. How is this achieved?_
Sorry for the seemingly ridiculous questions here but I’d rather ask and look a little stupid then spend the next few days implementing things incorrectly, then asking these same questions and then spending another fews days correcting mistakes.
[import]uid: 74503 topic_id: 17880 reply_id: 317880[/import]