Camera problem

Hey,

I want to make camera moves according to main hero. I watched Scroller and Potty Bird examples.

I set Parallax Enabled and Parallax Infinite to true in my Level. I put camera object. In my main.lua file i tried this:

camera = myLevel:getLayerObject("Camera","camera\_1") myLevel:slideCameraToPosition(200, 200, 200, easing.inOutQuad, onScrollFinished) \<\<--- nothing happened myLevel:move( 400, 0 ) \<\<----- nothing happened: screen doesn't change. Everything stay at the same positions. I thought whole screen will move to 400px to the left

I know this code isn’t enough to track hero  but I wanted to try this camera object and move function.

Is there some option what I should set or something?

Thanks.

You also need to enable the tracking as it is not enabled by default;

myLevel:trackEnabled(true)

If you look in the scroller2 demo it doesn’t enabled tracking initially because it uses the slideCamera function which will not work correctly if it is tied to an object.

In the onScrollFinished2 function you’ll see once the level scrolling preview has finished it then enables the tracking.

I tried myLevel:trackEnabled(true) but nothing happened.

I also realized that:

-- output:200, 201 print( "myLevel.cameraPos.x " .. myLevel.cameraPos.x .. ", " .. myLevel.cameraPos.y) myLevel:move( 600, 600 ) -- output: 800, 801 print( "myLevel.cameraPos.x " .. myLevel.cameraPos.x .. ", " .. myLevel.cameraPos.y) 

position changed but on the screen every object stay at the same position

Have you also checked that you have a parallax speed set on the layers that need to move?

The player layer should have a speed of 1.0 and all other layers should be relative to this (see the scroller2 demo).

Thanks a lot. This is what I needed. Now it’s working

You also need to enable the tracking as it is not enabled by default;

myLevel:trackEnabled(true)

If you look in the scroller2 demo it doesn’t enabled tracking initially because it uses the slideCamera function which will not work correctly if it is tied to an object.

In the onScrollFinished2 function you’ll see once the level scrolling preview has finished it then enables the tracking.

I tried myLevel:trackEnabled(true) but nothing happened.

I also realized that:

-- output:200, 201 print( "myLevel.cameraPos.x " .. myLevel.cameraPos.x .. ", " .. myLevel.cameraPos.y) myLevel:move( 600, 600 ) -- output: 800, 801 print( "myLevel.cameraPos.x " .. myLevel.cameraPos.x .. ", " .. myLevel.cameraPos.y) 

position changed but on the screen every object stay at the same position

Have you also checked that you have a parallax speed set on the layers that need to move?

The player layer should have a speed of 1.0 and all other layers should be relative to this (see the scroller2 demo).

Thanks a lot. This is what I needed. Now it’s working