I’m now writing a program that using container to mask a picture in a scene. But the behaviour of the container goes weird.
Here is my code:
[lua]---------------------------------------------------------------
– Require Parts
local storyboard = require ( “storyboard” )
– constants
– variables
–Create a storyboard scene for this module
local scene = storyboard.newScene()
–Create the scene
function scene:createScene( event )
print( “Creating HomeCounter Scene”)
local group = self.view
local container = display.newContainer(128, 128)
local img = display.newRect(50, 50, 30, 30)
img:setFillColor(255, 255, 255, 255)
container:insert(img, false)
group:insert(container)
end
function scene:enterScene( event )
print( “Entering HomeCounter Scene” )
– remove previous scene’s view
– storyboard.purgeScene( lastScene )
storyboard.purgeAll()
end
– Called when scene is about to move offscreen:
function scene:exitScene()
print( “Exiting HomeCounter Scene” )
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
print( “Destroying HomeCounter Scene” )
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene[/lua]
If I place “img” exactly inside the container region (as code), “img” will show up. However, if I place “img” outside the region, for example, display.newRect(-1, -1, 30, 30) or display.newRect(100, 100, 30, 30), nothing will be shown.
I’m using Corona Simulator (OSX) Version 2013.1202 (2013.8.28).
Please help me to solve the problem. Thanks for the help.