2D Camera Following a Player Character

Monkey Archive Forums/Monkey Tutorials/2D Camera Following a Player Character

evolving_developer(Posted 2015) [#1]
High guys, been using the Monkey X programming language for a couple months now and loving it. Doing the one game a month challenge and actually finding it quite challenging.

One of my most recent challenges was creating a simple 2D camera that followed a player as they moved. Turns out it was simpler than I thought, just not obvious.

Its a really long post and involves quite a bit of code. You can view the tutorial here:
Up is Down, Left is Right – How to create a 2D Camera Effect in Monkey X

Hope it helps!


Pakz(Posted 2015) [#2]
Who, I got lost in the code when the vectors came in :) I still need to spend more time learning/experimenting with vectors. It is so new to me still. I have books which explain with vectors and I really need to learn about it,

I never understood how to do this camera method. I learned over the years to create a map in memory (array) and draw on the screen what is visible with a for loop. Then move the visible thing on the screen when the player moves (scrolling) Your method sound like you draw the entire thing and set the viewing part on the camera, if I understand correctly. (note I have not spend a long time reading through your post yet.) I have not studied the code if you need to move each graphic in the code when the player moves or if this is handled already by the technique..

Can you make more examples from this method, or something you can paste into monkey and run? I find it hard to understand until now. I am always looking to expand my coding knowledge with new techniques and this might be something I should need to know.

Good that you are sharing your knowledge :)

btw : I can not see why your link is broken.


DruggedBunny(Posted 2015) [#3]
Looks like a cool tutorial, will be having a read -- just fixed your link, by the way! See the forum codes link just above the posting box.


evolving_developer(Posted 2015) [#4]
@Pakz
I got lost in the code when the vectors came in

The "Vectors" in this case simply represent value pairs (x, y) that are either some point on the screen, or a direction of an actor/character.
Your method sound like you draw the entire thing and set the viewing part on the camera, if I understand correctly.

You actually calculate everythings position, set the camera position, then draw anything that would show up in the view panel.
I have not studied the code if you need to move each graphic in the code when the player moves or if this is handled already by the technique.

Fortunately the technique keeps you from having to constantly recalculate.
Can you make more examples from this method, or something you can paste into monkey and run?

I am doing the #1GAM (1 game a month) challenge and will probably use this technique again. As far as code samples go, feel free to use the code straight off of github which I just realized is out of date and will push to in a bit.

@DruggedBunny
Thank you for pointing out the forum codes, had not seen that before as I am fairly new to the forum.