Camera tracking

Capture.jpg

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)

Are you trying to make the character move and the camera move with it? Or are you trying to make the back ground move but the character stay in one spot?

–SonicX278

I want to make the character move and the camera move with it 

Hi,

To enable scrolling like the scroller2 example you first need to enable scrolling on the level by setting ParallaxEnabled = True.

Once enabled you then have to set at which speed the layers will scroll i.e. ParallaxSpeedX & Y, your layers are set to 0.

Also your level needs to be bigger than one screen which yours is currently not so where are you scrolling to?

Once these things are in place you can use the scrolling methods like cameraFocus and slidetoCamera.

Take another look at the scroller2 demo and it should all become clear.

The docs here should also help http://www.retrofitproductions.com/level-director/utility-library/

Thanks

RetroFit

You can check out the egg breaker sample in the corona folder.

–SonicX278

Are you trying to make the character move and the camera move with it? Or are you trying to make the back ground move but the character stay in one spot?

–SonicX278

I want to make the character move and the camera move with it 

Hi,

To enable scrolling like the scroller2 example you first need to enable scrolling on the level by setting ParallaxEnabled = True.

Once enabled you then have to set at which speed the layers will scroll i.e. ParallaxSpeedX & Y, your layers are set to 0.

Also your level needs to be bigger than one screen which yours is currently not so where are you scrolling to?

Once these things are in place you can use the scrolling methods like cameraFocus and slidetoCamera.

Take another look at the scroller2 demo and it should all become clear.

The docs here should also help http://www.retrofitproductions.com/level-director/utility-library/

Thanks

RetroFit

You can check out the egg breaker sample in the corona folder.

–SonicX278