2

I've implemented a rectangle packing class similar to the one mentioned here. My ultimately goal is to pack a number of smaller sprites into a large spritesheet.

The difficulty I'm experiencing is figuring out a way to expand that algorithm to allow for static rectangles. That is: rectangles whose positions remain static during the packing process and are effectively treated as obstacles that are to be avoided.

Is there another algorithm I should be considering or perhaps a more efficient way to of doing this?

ndg
  • 2,585
  • 2
  • 33
  • 58

1 Answers1

0

I would say a good place to start would be here: http://en.wikipedia.org/wiki/Bin_packing_problem

Its hard to say without seeing your direct algorithm, but generally speaking you must find a way to set that bin to always be full so that nothing else can go there. Then your algorithm should be able to recognize what is and isn't empty space, so that it knows if it can put something there. A simple first fit algorithm would probably work if modified to your needs.

Hope that helps. Cheers.

metinoheat
  • 118
  • 1
  • 10