This commit is contained in:
Relintai 2024-03-02 14:56:37 +01:00
parent b59530099e
commit c27d8cb19a

View File

@ -181,6 +181,46 @@ void LayeredTileMap::draw_tile(RID p_canvas_item, const Vector2 &p_position, con
Rect2i source_rect = atlas_source->get_runtime_tile_texture_region(p_atlas_coords, 0);
tex->draw_rect_region(p_canvas_item, dest_rect, source_rect, modulate, transpose, Ref<Texture>(), p_tile_set->is_uv_clipping());
} else {
// RenderingServer::get_singleton()->canvas_item_add_animation_slice is implemented here in godot4:
// https://github.com/godotengine/godot/commit/94d31ac327a8fe6ff7c007b34cb25772bf96d17e
// RenderingServer::get_singleton()->canvas_item_add_animation_slice in godot4 is actually pretty clever
// But this implementation will be relatively easy to break due to the canvas batcher
// It would likely work with the code below, but it would be available to scripting too.
// Possible solution #1
// So I think it would make a lot more sense to do it in a different way, after the module is working.
// The api could look like:
// RenderingServer::get_singleton()->canvas_item_add_animated_sprite(RID ci, const Array &p_animation_data);
// p_animation_data:
// [i + 0]: duration
// [i + 1]: dest_rect
// [i + 2]: source_rect
// [i + 3]: modulate
// [i + 4]: transpose
// [i + 5]: normal
// [i + 6]: is_uv_clipping
// [i + 7]: Ref<Texture>
// This could create a new Command. It's internal data could be updated automatically when processing batches.
// This would make the api impossible to break in different cases.
// Also it would be simple to use for other things.
// Possible solution #2
// Handle animated tile updates here
// solution #1 is likely easier
// Possible solution #3
// Add more canvas items and show/hide them as necessary
// solution #1 is likely easier
ERR_PRINT("TODO Reimplement tile animations!");
/*
real_t speed = atlas_source->get_tile_animation_speed(p_atlas_coords);
real_t animation_duration = atlas_source->get_tile_animation_total_duration(p_atlas_coords) / speed;
real_t animation_offset = p_normalized_animation_offset * animation_duration;
@ -199,6 +239,7 @@ void LayeredTileMap::draw_tile(RID p_canvas_item, const Vector2 &p_position, con
time_unscaled += frame_duration_unscaled;
}
RenderingServer::get_singleton()->canvas_item_add_animation_slice(p_canvas_item, 1.0, 0.0, 1.0, 0.0);
*/
}
}
}