Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

This is pretty cool. How exactly does the packing algorithm work? Also what do the sliders on the right side do?

(+1)

Its just brute force, definitely not well optimized

1) compute container polygon bounds and initialize a placement cursor at the top left

2) each frame, attempt some placements (incrementing by the 1st slider)

3) rotate the shape in small increments (2nd slider)

4) translate the rotated shape to the cursor position

5) Check if it fits inside the container and does not overlap packed shapes

5.1) if valid, store it, animate effects, and update counters

6) advance the cursor right, wrap to next row when hitting container width

7) stop when the cursor reaches the container bottom


Source if you want to look, itll probably make more sense
https://github.com/cyprus327/Packer/blob/9f8136adce4e3cb9f1984bb3a37397fa11b1b41...