0
\$\begingroup\$

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 problemgame Play class

\$\endgroup\$
1
\$\begingroup\$

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);
\$\endgroup\$
0
\$\begingroup\$

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();
\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.