2
\$\begingroup\$

I am developing side scrolling game using AndEngine, and looking for additional camera control. I would like to view the whole level and then zoom/pan the camera to the left corner of the scene.

My whole scene is 4096px wide by 768px high, and my camera resolution is 1024px wide by 768px high. I used AndEngine's ZoomCamera class for this purpose and setZoomFactor to 0.1f to show whole game play.

So how do I pan the camera to the default left corner?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

The camera class has several methods to control its use. You've discovered some of them already with setZoomFactor. To move the camera directly you can use this:

setCenter(float pCenterX, float pCenterY) 

Where X and Y are the scene coordinates. If what you're asking is how to move the camera gracefully, rather than simply plopping it in the new location, there are a few ways to accomplish it. One is to use SmoothCamera instead of ZoomCamera. SmoothCamera extends ZoomCamera and comes with a few additional features. When you set the position of the smoothcamera it will "move" to that location, instead of jumping to it. You can also do things like setMaxVelocity() and such to control the speed.

Another option to give you some additional control is to create a sprite (it can be invisible if you like) and set the camera to chase the sprite. Then you can do fun things with the camera by manipulating the sprite using EntityModifiers (e.g., pathEntityModifier to move the camera around, arcmodifier to make it take a curved route there, etc.). I like this approach because you can make the sprite a cross-hair and let it be visible for debugging purposes; turn it off for production, so you know exactly where the camera is looking.

By the way, if you use the smoothcamera, there may be times when you still want it to jump to a location, rather than get there gracefully. For that purpose there's a setCenterDirect() method.

Hope this helps.

\$\endgroup\$
6
  • \$\begingroup\$ Sorry for late reply. I want following camera animation. play.google.com/store/apps/… This game has the thing what I want. Visualizing this I thing you give better answer. \$\endgroup\$
    – Siddharth
    Mar 7, 2013 at 17:49
  • \$\begingroup\$ I have to install it to see what you mean? :P \$\endgroup\$ Mar 7, 2013 at 17:50
  • \$\begingroup\$ Thanks and please know me the right way to do the things. \$\endgroup\$
    – Siddharth
    Mar 7, 2013 at 18:24
  • \$\begingroup\$ @Siddharth, my answer actually gives you a few ways of accomplishing this. Have you tried using the zoom camera features? \$\endgroup\$ Mar 7, 2013 at 19:02
  • \$\begingroup\$ If you want then I can post some code for this. I think I achieve 70% of the work. \$\endgroup\$
    – Siddharth
    Mar 8, 2013 at 4:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .