Currently, I use the following code to make the screen follow the main character:
float focusX = focus.currX + focus.width / 2,
focusY = focus.currY + focus.height / 2;
translateX = Math.min(stage.width - stage.visibleWidth, Math.max(0, focusX - stage.visibleWidth / 2));
translateY = Math.min(stage.height - stage.visibleHeight, Math.max(0, focusY - stage.visibleHeight / 2));
This code works fine as long as there is one
entity to focus on.
I want a code that supports 2-4 objects. I have seen games that have it. Basically, when the entities are to far from each other, the scaleX and scaleY are decreased to zoom out.
But I am not sure how to code this.