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'm developing a 2D shooter using AndEngine. At the moment I'm trying to make the camera follow the player. As I've understood the common approach is to use the SmoothCamera zooming it and setting the chased entity. The problem is that the camera follows the player WITH background moving also (RepeatingSpriteBackground), so it looks like the player doesn't move at all though the actual position changes. So I don't really get how to make the camera follow the player and have the background not moving. Thanks in advance.

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

Simplest approach would be to put the player sprite in a container at center of the container (X:0, y:0), and if he gets some speed, move him away from the center on distance equal to his speed. For example if you move right, you would first gain vx = 0.1 and move him to x:0.1 in the container, then vx = 2 and his distance would be 2 pixels on right from center of the container, and in the end when he's running vx = 10, he would be 10 pixels away from center. If the player character changes his speed smoothly, this will grant you a smooth camera follow effect.

You could multiply velocities by a constant value to make the effect stronger.

share|improve this answer
add 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.