I just completed code for stopping the camera to scroll when it reaches the map bounds. Firstly, here's how I do the camera in rendering:
graphics.drawImage (image, x-xCamera, y-yCamera, null);
Do this for your rendering method for players, tiles* anything you want to scroll.
This Is very simple. If you set the xCamera to 30, everything would be drawn 30 pixels to the left.
Alright, so that's the camera. He's how to center the camera on the screen:
public boolean stop = false;
if (stop) return: //if stop is true camera want scroll
xCamera = player.x - (screenWidth / 2);
yCamera = player.y - (screenHeight / 2);
Run these on your update tick.
If you ever want the camera to stop, simply make stop = true.
To stop the camera from scrolling below the x of 0, simply:
if (cameraX <0) cameraX = 0;
Same for max map, but check if the cameraX + screen width Is less then map max.
I hope this helps
Btw this is mainly for a top down legend of zwlda type gams, but it'll work for 2d. Also respond with any questipns