handling camera functions

Started by Hi!!, January 01, 2014, 02:42:56 PM

Previous topic - Next topic

Hi!!

I am working on android game. In this I am using JPCT framework. In this I want to use camera movement.As in some games the whole level view is viewed to the user( like in Angry Birds). I am putiing my code in OnDraw() function.
@Override
public void onDrawFrame(GL10 gl)
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVELEFT,2);


Now, when this executes it continuously goes to the left. I want to use various camera functions like it goes left them zoom in on particular object then zoom out and then move right;something like that. How I would be able to do so?? I am very new to programming.

Lobby

#1
cam.moveCamera moves the camera relative to it's current Position, so I think it's not useful for your purpose. Use cam.setPosition() instead to set it to a absolute coordiante. Zooming can be done by using different z-values ;) .


ps. Could you please put source code into code-tags (they look like [code_]Your Code[/code_] without the _) so it differs from the other text . This will look like:
My greate source.

Hi!!

oh! sorry and thanx... By the way my actual question is that How i would be able to set time. I mean camera moves to the left for 3 sec. then stop and get zoomed on particular object for sort of time then zoom out and move to the right.. Hope you are getting my question..  :(

Lobby

Oh, so you want to do a more complex thing. The bad news is, that you have to do the position calculations yourself. To move smoothly to a point you could do for instance the following thing in your update-Method:
SimpleVector pos = cam.getPosition();
SimpleVector delta = new SimpleVector(targetPos);
delta.sub(pos);
delta.scalarMul(deltaTime * 0.1f);
pos.add(delta);
cam.setPosition(pos);

This is pseudocode, so never tested or something like that. targetPos is a SimpleVector and the position the cam should move to. deltaTime is the time in senconds since last update. Here the cam should move slightly to targetPos becoming more and more slowly.

Hi!!

Thanx!!! I think it will help!!!!!!!