I've been using Godot on and off for a bit (v3.2.1.stable.official), and I was playing around with creating
TileMaps where some of the tiles are animated. Let's say I have this 64x64 texture with 16x16 tiles:
All of the tiles are static, except for the bottom four water tiles that are meant to be used as the frames for one animated tile.
What's the best way to do this in Godot? Here's what I've tried:
AtlasTexture resources, one for each frame, using the 64x64 texture as the atlas and using the region field to specify the location of the frame. Then, I created an
AnimatedTexture resource and assigned these four
AtlasTextures as its frames. I then added this
AnimatedTexure to the
TileSet. While I can place the tile in the
TileMap now, it doesn't animate - in fact, in only shows the "four-leaf clover" tile in the top-left corner of the original 64x64 texture. Out of curiosity, I also tried assigning this
AnimatedTexture to a
Sprite node, and got the same behavior: no animation and it only renders the four-leaf clover.
I then tried to export each frame as its own 16x16 png and import them into Godot as separate textures. I created another
AnimatedTexture and assigned each of these four textures as its frames. Then, I added this
AnimatedTexture to the
TileSet like before. This works - I can place the tile in the
TileMap and it animated as expected. However, it feels inefficient. Instead of one 64x64 texture containing everything, I now have five textures. I can't help but feel there's a better way to do this.
I also tried playing around with the
AnimatedSprite node, even though it can't be placed in a
TileMap. It takes in a
SpritesFrame resource and upon creating that resource, I noticed that it had a button to add frames from a sprite sheet:
I was then able to select the original 64x64 texture, select the four water frames, and voila! The
AnimatedSprite animates the water! So it looks like it is possible to animate specific regions of a texture. However, the plot thickens: I opened up the scene in a text editor, and the
AnimatedSprite is made using
AtlasTexture sub-resources referencing the original 64x64 texture! Which is precisely what I was trying to do in my first attempt (just with an
AnimatedTexture resource instead). I tried to save the
SpriteFrames resource as an external resource and add it to the
TileSet resource, but it doesn't appear that this is supported.
Based on this and the research I've done so far, it sounds like there's two options:
- Import each frame of animated tiles as their own textures
- Manually position
AnimatedSprites instead of using the
I'm not really satisfied with these solutions though, since the first one leads to tons of additional textures, and the second doesn't utilize the
TileMap. So, back to my original question: What's the best way to animate a tile in a
TileMap where its frames are contained in the same texture as other static tiles? Is it possible to use one texture for everything, or is there no other option than to export each frame as its own texture?
I appreciate any thoughts or insights on this!