diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-05-01 08:52:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-01 08:52:17 +0200 |
commit | 13aff5338a13ddf4303c19cf9d290d774a26da01 (patch) | |
tree | cd9e5b89125b7f3f05996654f8da9a2c52f6caf3 | |
parent | ad28d41a21e72c899aa3f6176d3504d0ea415c64 (diff) | |
parent | 13770ac08da64f252831f71f382f0470cef24077 (diff) |
Merge pull request #37939 from MrRevington/SpriteFramesEditoAtlasTextureSupport
Add AtlasTexture support in SpriteFrames Editor
-rw-r--r-- | editor/plugins/sprite_frames_editor_plugin.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 76e60bb014..34ff34d45b 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -154,14 +154,21 @@ void SpriteFramesEditor::_sheet_add_frames() { int fc = frames->get_frame_count(edited_anim); + AtlasTexture *atlas_source = Object::cast_to<AtlasTexture>(*split_sheet_preview->get_texture()); + + Rect2 region_rect = Rect2(); + + if (atlas_source && atlas_source->get_atlas().is_valid()) + region_rect = atlas_source->get_region(); + for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) { int idx = E->get(); int width = size.width / h; int height = size.height / v; int xp = idx % h; int yp = (idx - xp) / h; - int x = xp * width; - int y = yp * height; + int x = (xp * width) + region_rect.position.x; + int y = (yp * height) + region_rect.position.y; Ref<AtlasTexture> at; at.instance(); |