0
\$\begingroup\$

I’m using Tiled with LibGDX and I have some animated tiles. When the game is paused I would like their animation to be paused as well. Is this possible?

The map is drawn with mapRenderer.render() and if I'm not mistake, this is the class responsible for getting the corresponding animation. There doesn't seem to be a way to freeze time. Any help appreciated, I've been searching for a couple of hours and cannot find anything.

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

It is not supported, but you can implement it. If you use an OrthogonalTiledMapRenderer than extend it and override the beginRender method (it updates animation time) (similar you can do for other TiledMapRenderer-s). Magic of open source is that you can inspect the code and find a way.

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile;

public class OrthogonalTiledMapRendererStopStartAnimated extends OrthogonalTiledMapRenderer {
  private boolean animate=true;
  public OrthogonalTiledMapRendererStopStartAnimated(TiledMap map) {
    super(map);
  }

  public OrthogonalTiledMapRendererStopStartAnimated(TiledMap map, Batch batch) {
    super(map, batch);
  }

  public OrthogonalTiledMapRendererStopStartAnimated(TiledMap map, float unitScale) {
    super(map, unitScale);
  }

  public OrthogonalTiledMapRendererStopStartAnimated(TiledMap map, float unitScale, Batch batch) {
    super(map, unitScale, batch);
  }

  @Override
  protected void beginRender () {
    if (animate)
      AnimatedTiledMapTile.updateAnimationBaseTime();
    batch.begin();
  }

  public void setAnimate(boolean animate) {
    this.animate = animate;
  }

}

And to use it:

mapRenderer = new OrthogonalTiledMapRendererStopStartAnimated(tiledMap, UNIT_SCALE);
//...
mapRenderer.setAnimate(false); //TODO when you need 
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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