2
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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 : http://replicaisland.blogspot.com/2010/01/elusive-perfect-platformer-camera.html.

\$\endgroup\$
0

You must log in to answer this question.

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