A camera that follows the player
Level bigger than the screen? You need one.
My level is larger than the canvas and I need a camera: <paste the draw code> - A camera position, with everything drawn relative to it. Show me where the offset gets applied so I only do it in one place. - Smooth following with a lag, not locked rigidly to the player. - A dead zone in the middle so small movements don't shift the view. - Clamped to the level bounds — never show empty space past the edge. - Convert between screen and world coordinates, for mouse input. Keep the camera values in the config object so I can tune the feel.
A camera locked exactly to the player is nauseating. The lag and the dead zone are what make it feel like a camera rather than a rigid frame.