Hi. I am not 100% sure what you’re trying to do here and the use of the word sprites in your structure is a bit of a misnomer, but one possible way to organize this data as a module is:
-- save in a file called "spriteData.lua" for this example... -- local walkingGirl = {} walkingGirl.data = { width = 309, height = 494, numFrames = 10, sheetContentWidth = 1545, sheetContentHeight = 988} walkingGirl.sheet = graphics.newImageSheet("sprites/walking-girl.png", walkingGirl.data ) walkingGirl.seq = { name = "walking", start = 1, count = 10, loopCount = 0, loopDirection = "forward"} local meleeGirl = {} meleeGirl.data = { width = 385, height = 477, numFrames = 10, sheetContentWidth = 1925, sheetContentHeight = 954} meleeGirl.sheet = graphics.newImageSheet("sprites/melee-girl.png", meleeGirl.data) meleeGirl.seq = { name = "melee", start = 1, count = 10, loopCount = 0, loopDirection } local m = {} -- I'm not clear what this is m.units = {} m.units.girl = {img = "sprites/girl.png", timeBetweenAtk = 2350} } -- You're not storing sprites in this module, but parts used to make sprites, so I'm changing the -- names a bit from your original request. m.parts = {} m.parts.walking = walkingGirl m.parts.melee = meleeGirl return m
Then you could make sprites as follows
local sd = require "spriteData" local meleeSprite = display.newSprite( sd.parts.melee.sheet, sd.parts.melee.data ) local walkingSprite = display.newSprite( sd.parts.walking.sheet, sd.parts.walking.data )
This example still sucks though… keep reading below.