@@ -68,20 +68,23 @@ void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atla
6868 Vector2i tile_id = atlas_source->get_tile_id (tile_index);
6969 atlas_size = atlas_size.max (tile_id + atlas_source->get_tile_size_in_atlas (tile_id));
7070
71- Rect2i new_tile_rect_in_altas = Rect2i (atlas_offset + tile_id, atlas_source->get_tile_size_in_atlas (tile_id));
71+ Rect2i new_tile_rect_in_atlas = Rect2i (atlas_offset + tile_id, atlas_source->get_tile_size_in_atlas (tile_id));
7272
7373 // Copy the texture.
74+ int animation_columns = atlas_source->get_tile_animation_columns (tile_id);
75+ Vector2i animation_separation = atlas_source->get_tile_animation_separation (tile_id);
7476 for (int frame = 0 ; frame < atlas_source->get_tile_animation_frames_count (tile_id); frame++) {
7577 Rect2i src_rect = atlas_source->get_tile_texture_region (tile_id, frame);
76- Rect2 dst_rect_wide = Rect2i (new_tile_rect_in_altas.position * new_texture_region_size, new_tile_rect_in_altas.size * new_texture_region_size);
78+ Vector2i frame_coords = tile_id + (src_rect.size + animation_separation) * ((animation_columns > 0 ) ? Vector2i (frame % animation_columns, frame / animation_columns) : Vector2i (frame, 0 ));
79+ Rect2 dst_rect_wide = Rect2i (new_tile_rect_in_atlas.position * new_texture_region_size + (frame > 0 ? frame_coords : Vector2i (0 , 0 )), new_tile_rect_in_atlas.size * new_texture_region_size);
7780 if (dst_rect_wide.get_end ().x > output_image->get_width () || dst_rect_wide.get_end ().y > output_image->get_height ()) {
7881 output_image->crop (MAX (dst_rect_wide.get_end ().x , output_image->get_width ()), MAX (dst_rect_wide.get_end ().y , output_image->get_height ()));
7982 }
8083 output_image->blit_rect (atlas_source->get_texture ()->get_image (), src_rect, dst_rect_wide.get_center () - src_rect.size / 2 );
8184 }
8285
8386 // Add to the mapping.
84- merged_mapping[source_index][tile_id] = new_tile_rect_in_altas .position ;
87+ merged_mapping[source_index][tile_id] = new_tile_rect_in_atlas .position ;
8588 }
8689
8790 // Compute the atlas offset.
0 commit comments