Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am playing around a bit with the PushButton Engine for game development in Flash and have come across a need for a Camera like the Camera that follows Mario in Mario Games. Flashpunk has a nice implementation of it.

Does PushButton have it out of the Box?(I searched for it and didn't find, hence the question here). If not then if any of you have written a component for the same, or can guide in the direction, any help would be much appreciated. Thanks

share|improve this question

Well if you have searched for it, I guess it's not implemented. However, it's not extremely hard to do.

If you think about it moving a camera around is the same as moving the world around in the opposite direction. A camera implementation could be as simple as a Rectangle instance. On each frame, you would do something like :

world.x = - camera.x;
world.y = - camera.y;

If you want to follow a character in your world, it's simple as :

camera.x = character.x - camera.width / 2;
camera.y = character.y - camera.height / 2;

This will center the character in the screen (given that camera.width is equal to your screen width).

Note that this will not give you a nice camera movement. You might find some insight on good camera movement here :

share|improve this answer

Your Answer


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.