Help removing group/mask

I’ve made a simple game using the “flashlight” sample from Corona simulators library of samples.

I wanted to add a foreground and a backgrounds, so I made a simple display.newGroup() to make things easier, and made the mask, well mask, the entire group with image:setMask( mask ).

But now when I want to leave the scene, my flashlight mask, mask through the new scene. It obviously didn’t get removed.

I’ve tried every trick I could find to removing the mask and the group, but nothing seems to work. what am I doing wrong here?

relevant code:

--group before enterscene, so my button function won't complain about image being nil local image = display.newGroup() function scene:enterScene( event ) local group = self.view display.setStatusBar( display.HiddenStatusBar ) local centerX = display.contentCenterX local centerY = display.contentCenterY --Masking group local image = display.newGroup() -- background image local map = display.newImageRect( image, "img/background.png", display.contentWidth, display.contentHeight ) -- game objective image local map2 = display.newImageRect( image, "img/linx.png", 595, 451 ) map2.x = 340 map2.y = 300 image:translate( centerX, centerY ) local mask = graphics.newMask( "img/light\_cone.png" ) image:setMask( mask ) image.maskScaleX = 0.9 image.maskScaleY = 0.9 end function scene:exitScene( event ) local group = self.view image:setMask( nil ) mask = nil image:removeSelf( ) image = nil storyboard.removeScene("scripts.flashlightgame") end

Hi @coronazoo,

This appears to be a mix-up with your variable names and scope. You defined “image” as a display group outside of the “enterScene” function, then you defined a another image group (by the same name) inside of that function. Then, in the “exitScene” function, you remove the mask, but that is referencing the first instance of “image”, not the group that you masked.

If you’re not completely familiar and comfortable with Lua scope, please watch the following video:

http://www.youtube.com/watch?v=2ATlcGP2zMY

Take care,

Brent

Thanks! the video helped a ton

Happy coding

Hi @coronazoo,

This appears to be a mix-up with your variable names and scope. You defined “image” as a display group outside of the “enterScene” function, then you defined a another image group (by the same name) inside of that function. Then, in the “exitScene” function, you remove the mask, but that is referencing the first instance of “image”, not the group that you masked.

If you’re not completely familiar and comfortable with Lua scope, please watch the following video:

http://www.youtube.com/watch?v=2ATlcGP2zMY

Take care,

Brent

Thanks! the video helped a ton

Happy coding