Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: 0.2.9
-
Component/s: None
-
Labels:None
Description
This feature needs a full specification before the implementation begins.
Motivation
Currently, when the sizes of individual images within a sprite a varied (e.g. one very wide image and many smaller ones), there will be a lot of wasted space in the generated sprite image. While computing an optimal layout is (probably) computationally complex, a simple heuristic should solve the most common problems.
Implementation
Initial heuristic suggested by Frantisek:
1) set the sprite sheet width according the longest image.
2) sort the sprites according height
3) place sprite into image
4) try to find the longest sprite which will fit and place it on the right of previous one
5) if there will be no other sprite which will fit, start with 3) below all actually place sprites (on the new row)
Perhaps a tiny improvement: sprite fitting can consider all corner points (as opposed to starting a new line when an overfull occurs). These corner points are easy to maintain and this should be trivial. One could also combine this with checking rectangle overlap from all previous corner points and already placed sprites – this would allow packing sprites into empty areas above the current line. Attaching an example.