|Topic was automatically imported from the old Question2Answer platform.
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:
AtlasTextureresources, 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
AnimatedTextureresource and assigned these four
AtlasTextures as its frames. I then added this
TileSet. While I can place the tile in the
TileMapnow, 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
Spritenode, 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
AnimatedTextureand assigned each of these four textures as its frames. Then, I added this
TileSetlike before. This works - I can place the tile in the
TileMapand 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
AnimatedSpritenode, even though it can’t be placed in a
TileMap. It takes in a
SpritesFrameresource 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
AnimatedSpriteanimates 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
AnimatedSpriteis made using
AtlasTexturesub-resources referencing the original 64x64 texture! Which is precisely what I was trying to do in my first attempt (just with an
AnimatedTextureresource instead). I tried to save the
SpriteFramesresource as an external resource and add it to the
TileSetresource, 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!