I’ve not had chance to play around with scenes too much in Corona so this is probably a stupidly simple question, but…
In the standard composer functions, e.g. scene:create, you can reference self.view as the display group when adding objects. Like this:
function scene:create( event ) local sceneGroup = self.view myButton = display.newImageRect( sceneGroup, "button-image.png", 100, 40 ) end
But what I need to do now, is swap an image like this out for another, inside a custom function that a touch event points to. The replacement image needs to be added to the same display group but self.view doesn’t seem to be a thing outside of the scene functions. I thought I could just pass sceneGroup as a parameter, like this:
function scene:create( event ) local sceneGroup = self.view myButton = display.newImageRect( sceneGroup, "button-image.png", 100, 40 ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if( phase == "did" ) then myButton:addEventListener('touch', toggleImage(sceneGroup)) end end local function toggleImage(sceneGroup) myButton = display.newImageRect( sceneGroup, "button-image-2.png", 100, 40 ) end
But this approach just causes error.
Surely I’m missing something obvious here?