godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.15k stars 21.19k forks source link

Animations in TileMap #9179

Closed bojidar-bg closed 6 years ago

bojidar-bg commented 7 years ago

Part of what was mentioned in #5965, putting as separate issue for maintainability.

Why animations in tilemaps? "We already have AnimationPlayer for that!"

Yes, we do. Actually, we can already make animations with tilemaps, as evidenced by Minilens:

func _process(delta): # Move the acid
    acid_animation_pos = acid_animation_pos + delta
    if(acid_animation_pos > acid_animation_time):
        acid_animation_pos = acid_animation_pos - acid_animation_time
    level_tileset.tile_set_region(2, Rect2(64-64*acid_animation_pos/acid_animation_time,0,64,64))

Unfortunately, this is very hacky, and also forces update of all quadrants, as opposed to just quadrants which have the animated tile.

Ok, so what's the idea?

(terminology note: a TileMap is made up of cells. Each cell is of a specific type, know as a tile.)

After discussing the issue with @ArcFutahito on IRC, we agreed on the following idea:


About the implementation, I'm still not sure if we should keep cells with animations on separate canvas items, as to save some redraws. So, this is also something we might want to discuss.

eon-s commented 7 years ago

I have made some animations with AnimationPlayer changing texture region of individual tiles (or all the tileset), using frames could be more easy but depends on the tilemap, not regular tiles are allowed and using the region will be the best option.

bojidar-bg commented 7 years ago

@eon-s well, if you check that minilens example again, it was exactly what we did -- changing the region.

hubbyist commented 7 years ago

All cells with the same tile id would get the same frame at a given point in time; a cell added later would still get the same frame as other cells with the same tile.

May an integer phase value be added to this feature? Phase value of each tile will mean

# n: current frame number
# p: phase value
show frame[n + p] for this tile

It can be useful I think. Will it make additional performance impact?

bojidar-bg commented 7 years ago

@hubbyist if it is per-cell, it would probably require an additional byte per cell or so. Performance might be impacted if we run into CPU cache issues, but not way too much. In case we are doing this, we would probably get per-cell pausing of animation as well.

jonbonazza commented 6 years ago

This would be incredibly useful for when importing Tiled maps as well using the existing (and future) plugin from the asset lib (I think @vnen is the author?).

27thLiz commented 6 years ago

This will be possible in 3.1 with the new AnimatedTexture (coming soon).

kubecz3k commented 6 years ago

What is the status of the issue? Is it already solved in current master?

27thLiz commented 6 years ago

No, I totally forgot about this. Sorry, thanks for the reminder ^^

arnedirlelwy commented 6 years ago

Any idea on the release date of this? Really looking forward to it :)

vnen commented 6 years ago

With the new AnimatedTexture, can this be closed?

bojidar-bg commented 6 years ago

I think so yeah. Haven't used them, but from reduz's comments, it should work.

Going to close as it was implemented.

McSora commented 5 years ago

As reduz mentioned on twitter, the AnimatedTexture won't work for AtlasTexture. Now I wouldn't want to assume my ways to be the best practice but i am assuming that lots of people (if not most) working with the TileMap are using TextureAtlasses to manage lots of tiles.

What would now be the way to go if we consider the AnimatedTexture to solve our animated tiles issue? Should we keep every frame in a separate image file if a tile is animated or am I missing a better workflow?

MightyPrinny commented 5 years ago

you can animate the region of the atlas texture with an animation player selecting the texture of the tileset resource from the tilemap node then you add a modulate key frame so the tilemap updates, I'm not sure if this is efficient but it works.

NorielSylvire commented 1 year ago

AnimatedTexture requires you to use a different file (e.g png files) for each frame in the animation. In my case, each different type of tile has 50 frames of animation in total. So dragging and dropping 50 * 12 png files into the frames of each AnimatedTexture would be really inefficient and could easily lead to mistakes being made. I do not understand why AnimatedTexture wasn't made to work with spritesheets the way SpriteFrames does.