SmartSprites

Optimize layout of images within sprite to avoid large empty spaces

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Major 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)

Activity

Hide
Dawid Weiss added a comment -

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.

Show
Dawid Weiss added a comment - 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.
Hide
Stanisław Osiński added a comment -

One more thing before I forget: along with layout optimizations there should be an option to force individual images to be placed in separate rows. This could be done by means of the sprite-clear: before | after | both directive applicable at the individual image and sprite image level.

Show
Stanisław Osiński added a comment - One more thing before I forget: along with layout optimizations there should be an option to force individual images to be placed in separate rows. This could be done by means of the sprite-clear: before | after | both directive applicable at the individual image and sprite image level.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: