Hi I am rewriting my game and one of the big challenges I face is with images. Most of my screens have at least 50 to 60 images which takes up a lot of my 200 max variables and a lot of space in the code. There has to be a better way no? I tried with a function but it doesnt work, any ideas? Maybe both ways I do things are wrong!!! Any help is immensely appreciated.
Currently I make images like below:
local dW = display.contentWidth local dH = display.contentHeight local cX = display.contentCenterX local cY = display.contentCenterY local allObjects = {} bgGroup = display.newGroup() sceneGroup:insert( bgGroup ) local background = display.newImageRect(bgGroup, "background.png", dW\*3, dH ) local bottomBackground = display.newImageRect(bgGroup, "bottomBackground.png", dW\*.75, dW\*.22) local title = display.newImageRect(bgGroup, "title.png", dW\*.456, dW\*.19) table.insert(allObjects,background) table.insert(allObjects,bottomBackground) table.insert(allObjects,title) background.x=cX ; background.y=cY bottomBackground.x = cX ; bottomBackground.y = dH\*.85 title.x = cX ; title.y = dH\*.26
Function im trying:
I guess its not working too well because of the way i am passing variables to createImage function, in particular “varName” and “dispGroup”. In some of my game I create images with the local in the function and it works but this is done in a strategic way using a loop. These are more of static images and I need to call them later so defining the local within the function is not too strategic. I get I can call the images by a number in a table if I do define it within the function but this is hard to keep track of.
--writing overall idea real quick to give general concept local dW = display.contentWidth local dH = display.contentHeight local cX = display.contentCenterX local cY = display.contentCenterY local allObjects = {} local background, bottomBackground, title bgGroup = display.newGroup() sceneGroup:insert( bgGroup ) local function createImage(varName, dispGroup, imageLoc, xSize, ySize, xLoc, yLoc) varName = display.newImageRect(dispGroup, imageLoc, xSize, ySize ) table.insert(allObjects,varName) varName.x=xLoc ; varName.y=yLoc end createImage(background, bgGroup, "background.png", dW\*3, dH, cX, cY) createImage(bottomBackground, bgGroup, "bottomBackground.png", dW\*.456, dW\*.19, cX, dH\*.85)