Help needed for Android platformer game with static background but moving camera.

Hi,

I am new to Corona. I was looking for a code to move the camera to show only the images on the stage.

For example angry birds.

At the beginning of the game the camera shows the whole scene. i.e. where the pigs are and how the obstacles look. Then the camera focuses on the catapult and the bird.

After that if the user wants he can scroll the screen to look at the obstacles again.

Is there any sort of tutorials available to set up such environment?

If not can somebody help with some code?

I was able to write the below code which scrolls the background. However, the players and platform stay at the same place making the code worthless. Thanks for taking time to answer.

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local physics = require( "physics" ) physics.start() local background = display.newImageRect("bg01.png",1500,800) background.x = 50 local myPlayer = display.newImage("playernew.png", 76, 94) physics.addBody(myPlayer) myPlayer.x = 100 myPlayer.y = 100 local otherPlayer = display.newImage("player.png") physics.addBody(otherPlayer) otherPlayer.x = 100 otherPlayer.y = 200 local platform = display.newImageRect("p1.png", 1500, 50) physics.addBody( platform, "static", { density=1, friction=0.5, bounce=0.2 } ) platform.x = 50 platform.y = 300 local function OnTouch(event) local touchedObject = event.target if(event.phase == "began") then touchedObject.previousX = touchedObject.x touchedObject.previousY = touchedObject.y display.getCurrentStage():setFocus( event.target ) elseif(event.phase == "moved") then touchedObject.x = (event.x - event.xStart) + touchedObject.previousX touchedObject.y = (event.y - event.yStart) + touchedObject.previousY elseif ( event.phase == "ended" or event.phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) end return true end xMin = 70; xMax = 400 local function backTouch( event ) local t = event.target if(event.phase == "began") then -- Make target the top-most object -- Store initial touch position on the actual object - prevents jumping when touched t.previousX = t.x display.getCurrentStage():setFocus( event.target ) elseif(event.phase == "moved") then t.x = (event.x - event.xStart) + t.previousX if (t.x \< xMin) then t.x = xMin end if (t.x \> xMax) then t.x = xMax end elseif ( event.phase == "ended" or event.phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) --t.y = event.y - t.yStart end return true end myPlayer:addEventListener("touch",OnTouch) otherPlayer:addEventListener("touch",OnTouch) background:addEventListener("touch",backTouch) platform:addEventListener("touch",backTouch)

You might want to look at this complete project:

https://coronalabs.com/blog/2016/02/02/corona-cannon-a-new-corona-sdk-sample-game/

It should have similar camera code.

Rob

You might want to look at this complete project:

https://coronalabs.com/blog/2016/02/02/corona-cannon-a-new-corona-sdk-sample-game/

It should have similar camera code.

Rob