Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CelestialCreator |
I’ve been using Godot on and off for a bit (v3.2.1.stable.official), and I was playing around with creating TileMap
s 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:
-
Create four
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 anAnimatedTexture
resource and assigned these fourAtlasTexture
s as its frames. I then added thisAnimatedTexure
to theTileSet
. While I can place the tile in theTileMap
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 thisAnimatedTexture
to aSprite
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 thisAnimatedTexture
to theTileSet
like before. This works - I can place the tile in theTileMap
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 aTileMap
. It takes in aSpritesFrame
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! TheAnimatedSprite
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 theAnimatedSprite
is made usingAtlasTexture
sub-resources referencing the original 64x64 texture! Which is precisely what I was trying to do in my first attempt (just with anAnimatedTexture
resource instead). I tried to save theSpriteFrames
resource as an external resource and add it to theTileSet
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
AnimatedSprite
s instead of using theTileMap
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!