Recommended way to set up game camera?

Hi all,

I was wondering what the recommended way to set up a camera is.

I have always used an x and y offset variable and drawn everything based off of that. So all the map objects would move as the xOffset and yOffset changes. But I recently heard that you could just use g.translate(x, y) to move the actual origin of the drawing area, which could be used for a game camera.

So, which is the standard way to set up a camera?

Thank you all very much

Either way works, but translate() is much less work. You can also give it more complicated transforms like rotation with setTransform().

There is no right or standard way to setup a “camera”. A camera doesn’t exist in game dev, you are simply moving objects to make it look like the world is scrolling, so whatever you do to achieve this effect is fine!

Thank you all very much! I think I am going to try and use the translate() from now on because it is definitely a lot less work.