Hello,
I’m new to Corona and just started implementing scene transitions in a sample game using composite, but have problems with positioning of border walls on screen (need them to add boundaries for objects movements).
I tried something like this:
function scene:create( event ) local sceneGroup = self.view local borderGroup = display.newGroup() physics.start() -- create background image background = display.newImageRect( sceneGroup, "sc1.jpg", 1024, 768 ) background.anchorX = 0 background.anchorY = 0 background.x, background.y = 0, 0 -- create wall objects topWall = display.newRect( 0, 0, display.contentWidth, 10 ) bottomWall = display.newRect( 0, display.contentHeight - 10, display.contentWidth, 10 ) leftWall = display.newRect( 0, 0, 10, display.contentHeight ) rightWall = display.newRect( display.contentWidth - 10, 0, 10, display.contentHeight ) -- make them physics bodies physics.addBody(topWall, "static", {density = 1.0, friction = 0, bounce = 1}) physics.addBody(bottomWall, "static", {density = 1.0, friction = 0, bounce = 1}) physics.addBody(leftWall, "static", {density = 1.0, friction = 0, bounce = 1}) physics.addBody(rightWall, "static", {density = 1.0, friction = 0, bounce = 1}) butterfly = display.newImageRect(sceneGroup,"butterfly.png",110,102) butterfly.x = 5 butterfly.y = 0.33 \* display.contentHeight snail = display.newImageRect(sceneGroup,"snail.png",110,91) snail.x = display.contentWidth - 40 snail.y = 0.75 \* display.contentHeight physics.addBody(butterfly,"kinematic", {isBullet = true}) physics.addBody(snail,"kinematic", {isBullet = true}) borderGroup:insert(leftWall) borderGroup:insert(rightWall) borderGroup:insert(topWall) borderGroup:insert(bottomWall) borderGroup:insert(snail) borderGroup:insert(butterfly) snail:addEventListener("collision", onCollision) butterfly:addEventListener("collision", onCollision) physics.pause() end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "did" then physics.start() background.touch = onPageSwipe background:addEventListener( "touch", background ) snail:setLinearVelocity(-14,0) timer.performWithDelay(500, moveButterflyRandomly, 13); end end function moveButterflyRandomly() butterfly:setLinearVelocity(math.random( 40,40 ), math.random( 20,60 ) ); end local function onCollision(event) print(event.phase, snail:getLinearVelocity()) print(event.phase, butterfly:getLinearVelocity()) end
however the walls are not correctly positioned as seen on the screenshot:
http://www.dropbox.com/s/nfjtpx47fp4hbde/scene1.png?dl=0
and there is no interaction between moving objects (butterfly, snail) and walls - objects are above them and are moving out of scene boundaries.
I tried also code without explicitly inserting objects into borderGroup , but with no effect.
Thank you for your help.