Problem:Camera Move with transition.to

I tried to make camera move in vertical direction by referencing ghost&monster code.

But I am confused about how to use transition.to API. I read the document but still do not understand well.
my transtion.to API does not call onComplete event.
How can I make the camera to move(smoothly) when player moved to some specific distance?

[lua]local physics = require(“physics”);
local player = require(“player”).new();
local camera = display.newGroup();
camera:insert(player);
physics.addBody(player,{density = 0.1, friction = 0.1, bounce = 0.1});

local times = 0;
function update()
if(player.y > -320*times)then
times = times +1;
transition.to(camera, { time=1000, y = -320*times, onComplete=listener1 } );
end

end
local listener1 = function( obj )
print( "Transition 1 completed on object: " … tostring( obj ) )
end

Runtime:addEventListener(“enterFrame”,update);[/lua] [import]uid: 65906 topic_id: 16415 reply_id: 316415[/import]

Could anybody please help? [import]uid: 65906 topic_id: 16415 reply_id: 61828[/import]

Hi there ,
I had the same camera problem in my app. i solved it by using the ballbreaker sample code.
For my game this was the code

if (ball.x > W/2 ) then
game.x=-ball.x+W/2
end

I basically load the ball in the left half of the screen. When the ball goes beyond Half the screen (W/2) i update the game group
Note that i again had to minus the ball’s x position to centralize it. else it goes past the screen
I think the transitions you are using to make the camera move is too complex. Try like the above method.
Hope that helps. [import]uid: 76873 topic_id: 16415 reply_id: 61833[/import]

Also, check out the egg breaker code. That code was MAGIC for me.

as .anand.cegc said and I can add. You can manipulate the values so when you have a large playing field, when your “ball” gets to the end, the scrolling stops and you don’t see “outside” the level.

You can do this vertically as well, so when you are moving around the level, you stop scrolling when you get within sight of the wall (takes some fine tuning).

Let me know, I have some sample code I wrote which helps. I’m not at the dev station right now so I’ll leave it at that :slight_smile:

ng [import]uid: 61600 topic_id: 16415 reply_id: 61884[/import]

@anand.cegc and @nicholasclayg

Thanks for your advice.

My object has body as “dynamic”…
It moves so fast,I cannot control…

I don’t know how to control camera
[import]uid: 65906 topic_id: 16415 reply_id: 62091[/import]

Your reference to listener1 is before the function is defined. You can either move the function up to the beginning of your program or add a forward reference. You are probably seeing a “nil” error in the terminal.

local listener1 -- forward reference ... function listener1( obj ) ... end

You also need to be careful when using transitions and other display objects commands on physics objects. You may get unexpected results. [import]uid: 7559 topic_id: 16415 reply_id: 62098[/import]

@Tom
I already got that unexpected result.
I wonder how I solved that.
The object which dynamic fall too fast.
I tried to adjust setGravity() but it did not work.
The transition is reload so fast so I can see my object duplicate its body.
[import]uid: 65906 topic_id: 16415 reply_id: 62373[/import]

You could make a “master group” and move the master group… If that’s what you’re looking for! [import]uid: 95032 topic_id: 16415 reply_id: 62379[/import]

@Larochepower

I don’t understand what do you mean “master group” [import]uid: 65906 topic_id: 16415 reply_id: 62652[/import]

A master group would be a group with every object in it… Then you move the Mastergroup… See what I mean? [import]uid: 95032 topic_id: 16415 reply_id: 62825[/import]