How to use storyboard with a display object in another module

I’m building a game, and am using storyboard. On enterScene I call my display object lilEnem from another module. I can’t remove him from memeory when I change scenes, and I don’t know how to insert him into scene.view since it’s a separate file.

[lua]

function level1:enterScene()

local level1Group = level1.view

print( “enteredScene” )

local function goHome(event)

storyboard.removeAll( )

storyboard.gotoScene( “mainMenu” )

end

local function pauseUi (event)

local pauseButton = display.newImage(“assets/graphics/gameplay/UI/pause/pause.png”, display.contentWidth- 25, 25)

pauseButton:addEventListener( “tap”, goHome )

level1Group:insert( pauseButton )

end

pauseUi()

–Load and play game song when entered scene

gameAudio.gamePlay()

– Spawns lilEnems

local function spawnLilEnem (event)

– Checking myData module for lilEnem ID

–Storing in local id

local id = myData.lilEnemId

–lil Enem will spawn in time math.random gives

local randomSpawnTime = math.random(0,5000)

–Calls spawnEnem Module

lilEnem.spawnEnem(id)

–Adds 1 to id to give each enem unique id

myData.lilEnemId = myData.lilEnemId + 1

–timer will call this function at random times

local spawnEnemTimer = timer.performWithDelay( randomSpawnTime, spawnLilEnem, 1 )

–When id reachs == number it will stop spawning enems

–Number is the highest numbered lil Enem ID

–This statement decides how many lilEnems spawn

if id == 5 then

timer.cancel( spawnEnemTimer )

end

end

spawnLilEnem()

–Call score from scoreData module

–score = 0 in scoreDate module

local score = display.newText(scoreData.score, display.contentWidth/2, 50, nil, 30)

end

[/lua]

Hi @nzachary46,

What is your other module? If it returns an object, then you can simply add that object to the scene after it returns. Another option is to pass the scene’s view handle to that module and insert the object inside that module.

Best regards,

Brent

Hi @nzachary46,

What is your other module? If it returns an object, then you can simply add that object to the scene after it returns. Another option is to pass the scene’s view handle to that module and insert the object inside that module.

Best regards,

Brent