Hi guys,
So I’m trying to clean up my code by adding some functions to a separate lua file. This way, I’d not always have to copy and paste the code when I have to use it again in my levels.
Now, I was able to make functions work across the files, but how can I manage to transfer objects like rectangles, images etc from the separate file to the levels? So for example
I’ve got this code:
----------------------------------------------------------------------------------------- -- -- cityBackgroundPowerupSelection.lua -- ----------------------------------------------------------------------------------------- local M = {} local loadsave = require("loadsave") settings = loadsave.loadTable("settingsGame.json", system.DocumentsDirectory) local screenW, screenH, halfW = display.contentWidth, display.contentHeight, display.contentWidth\*0.5 local centerX, centerY = display.contentCenterX, display.contentCenterY local centerX, centerY = display.contentCenterX, display.contentCenterY local actualW = display.actualContentWidth local actualH = display.actualContentHeight local originX = display.screenOriginX local originY = display.screenOriginY local maxWidth = display.screenOriginX + actualW local maxHeight = display.screenOriginY + actualH local background1 background1 = display.newRect(centerX, centerY, actualW, actualH) background1:setFillColor(41/255, 128/255, 185/255) background1.alpha = 0 background1 = M.background
I’d now like to add the background to my sceneGroup in my levels file. How could I do this?
Kind regards
Bram