Question about a tiled use case

Hello,

I have a use case I am not sure what is the best way to handle it. I want to create a map in tiled with coins scattered across the map for a player to collect, I want the coins to rotate, I have few ways to do it but not sure what is the common practice,

Approach 1:

  • Create a tiled layer called “Coins” and add all the coins as tiles on it.
  • In the game loop, I check if there is a coins in a tile using the
layer = map.getLayer("coins")
for (int x = 0;x < layer.getWidth();x++)
    for (int y = 0; y < layer.getHeight();y++) {
        if (layer.getTile(x, y).visible && !layer.getTile(x,y).empty())
            rotateTileAt(x,y)
    }

Approach 2

  • Using object group of coins.
  • I create a tile layer with the coins scatterd.
  • I create object group and select the coins from the tile layer to add them to the object group.
  • In game loop I query the group and rotate.

Any ideas what is the practice here?

Thanks

first of all, i think i don’t really get it what do you mean with “rotate”
with your current approach, you’ll get rotated coin with “stiff” rotation.

if you want to achive something like this:

you can use animated tile

Thanks for the reply, do you mean to use the animation editor within tiled?

well, yes if you want something like above

While the Tile Animation Editor may help defining your animation (if you need to, because there’s many other ways to define animated sprites), it does not help you with implementing the animation in your game, which seems to be what this question is mainly about.

It does not really matter whether your coins are on a tile layer or an object layer. If you do not mind that all coins rotate in sync (like they do when you define the animation in Tiled), you can have a single animation going on and just take its current frame whenever you draw your tile. If you want to randomize or otherwise vary the coin rotation, you’ll need to drive an animation for each coin tile or object like you’re doing in the code you posted.