When I use screenGroup:insert(img) I get "attempt to index global 'screenGroup' (a nil value)".
How do I add the img objects created in the onTouch function to the screenGroup to ensure they are removed when I change scenes?
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local function goToTitle(event)
if event.phase == "began" then
storyboard.gotoScene( "titleScreen", "fade", 400 )
end
return true
end
local onTouch = function(event)
if event.phase == "began" then
local img = display.newImage("shut_up_black.jpg")
img:addEventListener( "touch", goToTitle )
img.width = 100
img.height = 100
img.x = event.x
img.y = event.y
screenGroup:insert(img)
return true
end
end
function scene:createScene( event )
local screenGroup = self.view
local bg = display.newImage("bg1.jpg")
screenGroup:insert( bg )
Runtime:addEventListener("touch", onTouch)
end
function scene:enterScene( event )
end
function scene:exitScene( event )
end
function scene:destroyScene( event )
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener( "destroyScene", scene )
return scene