# Why is the Tilemap not fitting the screen?

I have a background image which I made it in tiled map editor of width 40tiles and height of 8tiles.When I run the game the tilemap bounces with the player and I can see the black portion of the screen.The game screen width and height is 320 by 256.Here is the problem Play class

## 2 Answers

You'll want to make sure the position of the camera never goes outside the bounds of the map. Find the map's boundaries, then use MathUtils.clamp() on the camera's X and Y positions to ensure this. For example:

cam.position.x = MathUtils.clamp(cam.position.x, mapLeftBoundary, mapRightBoundary);
cam.position.y = MathUtils.clamp(cam.position.y, mapBottomBoundary, mapTopBoundary);


If you don't want the camera to jump with the player the set the camera Y-position to half the grid height:

cam.position.set(player.getPosition().x+40/2 , 8/2,0);
cam.update();