Animations dissapear once its coordinates are passed by the game Camera

Hello guys,

I am able to create idle, background animations on Tiled just fine.

I am creating a 2d platform game using libgdx and eclipse. Once the tmx file is loaded and I run the game, the background animations work as expected – but once the player starts to move, the game camera will follow the player and once the game camera passes the xy coordinates of the background animation, the animation disappears. Lets say the animation is 500 pixels wide and it’s centered at (0,0) at the bottom left corner of the screen (as you can see this animation fills a good portion of the background) once the camera hits (1,0) the entire 500 pixel animation disappears. This looks very odd indeed.

Now this is a good thing, because it means the game is not rendering the animation when its not in the camera’s view, but I only wish I could control these coordinates. Hopefully I am not missing something obvious. Is there anyway to fix this?

Kind regards

Sounds like libgdx is not taking into account that some tiles may be larger than the grid cells when rendering a tile layer. You could try to use a tile object for this animation instead, but I do not know whether libgdx supports that. Alternatively you may be able to fake the camera view to make sure it renders some more “out of view” tiles.

You should probably try asking this question in the libgdx community, where you may have a better chance of getting a satisfying answer.

Hello bjorn,

Thank you for your reply. It will work with an object layer but I have to add a ton of code to make it work. With the regular tile layer, the animations worked nicely without the addition of code. It is simply more clean and efficient this way which is why I was hoping for a solution. But thank you, I will check out the libgdx community.

Within Tiled, you could add an offset to render the tiles at (this is a tileset property). But wouldn’t your large animation graphic have the same problem on both sides of the screen? Cause then you can’t really solve it this way.

Indeed, the offset would have to work for both directions of the screen and ultimately the top and down directions as well. Thank you for your feedback and ideas!