Several ways to skin a cat…
What you’re doing is good, but when you need to update your spritesheet with new graphics, you’re stuck with changing it in every file. I normally do something like
--hero.lua local H = {} local function createHero() local options = { width = 50, height = 50, numFrames = 4, sheetContentWidth = 100, sheetContentHeight = 100 } local imageSheet = graphics.newImageSheet( "media/images/player/hero1.png", options, true ) local sequenceData = { { name="idle", start=1, count=1 }, { name="back", start=2, count=1 }, { name="walking", frames={ 2,3,4 }, loopDirection = "bounce", time=350 }, { name="running", start=4, count=1, time=pL+150 }, { name="stopped", start=4, count=1 }, { name="ready", start=3, count=1 }, } H.hero = display.newSprite( imageSheet, sequenceData ) H.hero:setSequence("stopped") H.hero:play() end H.createHero = createHero return H
--scene1.lua local hero = require ("hero") function scene:enterScene( event ) local group = self.view hero.hero() hero.hero.x = 200 hero.hero.y = 100 end
This way you can avoid globals and have the ability to access your sprites from a module, keeping code relatively tidy.