How to make camera move with character like Scroller2 example ?
display.setStatusBar( display.HiddenStatusBar ) \_W = display.contentWidth \_H = display.contentHeight local LD = require('lib.LD\_LoaderG2') local physics = require ("physics") physics.start() physics.setGravity(0,49.8) local myLevel = {} myLevel = LD:loadLevel("AssetTest") local ball = nil local btnPressed = false function moveTo(object, params) local T = display.screenOriginY -- Top local L = display.screenOriginX -- Left local R = display.viewableContentWidth - L -- Right local B = display.viewableContentHeight - T-- Bottom local cX, cY = display.contentCenterX, display.contentCenterY object.x, object.y = 0, 0 local bounds = object.contentBounds local offsetX = (bounds.xMax + bounds.xMin) \* 0.5 local offsetY = (bounds.yMax + bounds.yMin) \* 0.5 local hW, hH = 0.5 \* object.contentWidth , 0.5 \* object.contentHeight if params.left then object.x = params.left+L + hW - offsetX elseif params.right then object.x = R-params.right - hW - offsetX elseif params.centerX then object.x = params.centerX + cX - offsetX end if params.bottom then object.y = B-params.bottom - hH - offsetY elseif params.top then object.y = params.top + T + hH - offsetY elseif params.centerY then object.y = params.centerY + cY - offsetY end return object end local function jump(e) if e.phase == "began" then if e.x \> \_W/2 then local vx,vy = ball:getLinearVelocity() dy = -450 dx = vx ball:setLinearVelocity(dx,dy) else end end end local function move() ball:applyForce(speed,0,ball.x,ball.y) end local function onTouch(e) if e.x \< \_W/2 then if e.phase == "began" then if e.target.name ~= ButtonName then local vx,vy = ball:getLinearVelocity() vx = vx \* 0.5 ball:setLinearVelocity(vx,vy) end if e.target.name == "leftB" then speed = -20 else speed = 20 end Runtime:addEventListener("enterFrame",move) elseif e.phase == "moved" then elseif e.phase == "ended" then btnPressed = false Runtime:removeEventListener("enterFrame",move) ButtonName = e.target.name end end end local leftB = display.newImage("Images/left\_right.png") moveTo(leftB,{left=30,bottom=30}) leftB.name = "leftB" leftB:addEventListener("touch",onTouch) local RightB = display.newImage("Images/left\_right.png") RightB.xScale = -1 RightB.name = "RightB" moveTo(RightB,{left=100,bottom=30}) RightB:addEventListener("touch",onTouch) ball = myLevel:getLayerObject("bg","ball").view camera = myLevel:getLayerObject("Camera","camera\_1") --myLevel:setCameraFocus(ball) --myLevel:trackEnabled(true)