Problem about display.newContainer

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.

Hi @raymondpineapple,

Containers are a feature of the advanced graphics 2.0 engine. They are not available in public build #1202. If you want to achieve a similar effect in the 1.0 engine, you’ll need to apply a mask to the image (or group). This process is discussed in the Masking guide here:

http://docs.coronalabs.com/guide/media/imageMask/index.html

Sincerely,

Brent Sorrentino

Thank you for your reply.

I use imageMask before. The problem is, it needs the image as the mask. And the edge of the display image is blurred, although I’m not sure if it is because I did the scaling on the mask.

Anyway, I’ll use imageMask instead of container now. Thanks.

Hi @raymondpineapple,

Containers are a feature of the advanced graphics 2.0 engine. They are not available in public build #1202. If you want to achieve a similar effect in the 1.0 engine, you’ll need to apply a mask to the image (or group). This process is discussed in the Masking guide here:

http://docs.coronalabs.com/guide/media/imageMask/index.html

Sincerely,

Brent Sorrentino

Thank you for your reply.

I use imageMask before. The problem is, it needs the image as the mask. And the edge of the display image is blurred, although I’m not sure if it is because I did the scaling on the mask.

Anyway, I’ll use imageMask instead of container now. Thanks.