Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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. –  Siddharth Mar 7 '13 at 17:49
    
I have to install it to see what you mean? :P –  Cameron Fredman Mar 7 '13 at 17:50
    
Thanks and please know me the right way to do the things. –  Siddharth Mar 7 '13 at 18:24
    
@Siddharth, my answer actually gives you a few ways of accomplishing this. Have you tried using the zoom camera features? –  Cameron Fredman Mar 7 '13 at 19:02
    
If you want then I can post some code for this. I think I achieve 70% of the work. –  Siddharth Mar 8 '13 at 4:20
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.