1

Doing simple platformer game with LibGDX and Android. For me not a problem to do an animation with sprite sheets but I'm wondering about efficient way to do "static animation for map elements"... for example:

  1. stars on the sky

  2. moving grass

  3. moving trees

Such kind of elements may be a lot on the map and I can define such object layer in my tiled map and inject all those animated elements when game started but in that case when map builded and all elements inserted these animated elements will be animated simultaneously even if they are outside of Game Camera. What the efficient way of doing multiple 2D animations for static map objects?

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
Lugaru
  • 1,430
  • 3
  • 25
  • 38

1 Answers1

1
int frameSize=2; 
TiledMap map;
String tileSetName="stars";
int firstTileId=3,secondTileId=4;

Array<StaticTiledMapTile> frameTiles=new Array<StaticTiledMapTile>(frameSize);
frameTiles.add((StaticTiledMapTile) map.getTileSets().getTileSet(tileSetName).getTile(firstTileId));
frameTiles.add((StaticTiledMapTile) map.getTileSets().getTileSet(tileSetName).getTile(secondTileId));

AnimatedTiledMapTile animatedTile=new AnimatedTiledMapTile(1/2f, frameTiles);

Now AnimatedTile is ready, but not in map. Check if particular cell is in inside screen or with some offset set to particular cell where you want to place your AnimatedTile and when goes offscreen you can remove that tile.

myLayer.getCell(x,y).setTile(animatedTile);
Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
  • is it possible to set animated tile to the object layer of my tiled-map? Simply curious how it will look like because tiled map cell size 10*10px and animation sprite sheet contains frames 27*15px which are PNG with transparent bg. – Lugaru Jul 11 '17 at 21:36
  • I don't think so, it is possible to set animated tile to object layer. I used with tile layer – Abhishek Aryan Jul 11 '17 at 21:47
  • 1
    Let's consider star, that may contains 4 frames for animation, so create tileset for that star png, then after that tileset contain 4 tile each one is the frame of star animation then get all frame and create Animated tile and put into map where you want. – Abhishek Aryan Jul 11 '17 at 21:52