@@ -70,20 +70,25 @@ void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atla
7070 Vector2i tile_id = atlas_source->get_tile_id (tile_index);
7171 atlas_size = atlas_size.max (tile_id + atlas_source->get_tile_size_in_atlas (tile_id));
7272
73- Rect2i new_tile_rect_in_altas = Rect2i (atlas_offset + tile_id, atlas_source->get_tile_size_in_atlas (tile_id));
73+ Rect2i new_tile_rect_in_atlas = Rect2i (atlas_offset + tile_id, atlas_source->get_tile_size_in_atlas (tile_id));
7474
7575 // Copy the texture.
7676 for (int frame = 0 ; frame < atlas_source->get_tile_animation_frames_count (tile_id); frame++) {
7777 Rect2i src_rect = atlas_source->get_tile_texture_region (tile_id, frame);
78- 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 new_position = new_tile_rect_in_atlas.position * new_texture_region_size;
79+ if (frame > 0 ) {
80+ new_position += src_rect.size * Vector2i (frame, 0 );
81+ atlas_size.x = MAX (frame + 1 , atlas_size.x );
82+ }
83+ Rect2 dst_rect_wide = Rect2i (new_position, new_tile_rect_in_atlas.size * new_texture_region_size);
7984 if (dst_rect_wide.get_end ().x > output_image->get_width () || dst_rect_wide.get_end ().y > output_image->get_height ()) {
8085 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 ()));
8186 }
8287 output_image->blit_rect (atlas_source->get_texture ()->get_image (), src_rect, dst_rect_wide.get_center () - src_rect.size / 2 );
8388 }
8489
8590 // Add to the mapping.
86- merged_mapping[source_index][tile_id] = new_tile_rect_in_altas .position ;
91+ merged_mapping[source_index][tile_id] = new_tile_rect_in_atlas .position ;
8792 }
8893
8994 // Compute the atlas offset.
@@ -110,6 +115,13 @@ void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atla
110115 int changed_id = -1 ;
111116 if (alternative_id == 0 ) {
112117 merged->create_tile (tile_mapping.value , atlas_source->get_tile_size_in_atlas (tile_mapping.key ));
118+ int count = atlas_source->get_tile_animation_frames_count (tile_mapping.key );
119+ merged->set_tile_animation_frames_count (tile_mapping.value , count);
120+ for (int i = 0 ; i < count; i++) {
121+ merged->set_tile_animation_frame_duration (tile_mapping.value , i, atlas_source->get_tile_animation_frame_duration (tile_mapping.key , i));
122+ }
123+ merged->set_tile_animation_speed (tile_mapping.value , atlas_source->get_tile_animation_speed (tile_mapping.key ));
124+ merged->set_tile_animation_mode (tile_mapping.value , atlas_source->get_tile_animation_mode (tile_mapping.key ));
113125 } else {
114126 changed_id = merged->create_alternative_tile (tile_mapping.value , alternative_index);
115127 }
0 commit comments