0 Favourites

Filling a space with non-overlapping sprites

This forum is currently in read-only mode.
  • I want to fill the layout with non-overlapping sprites. Unfortunately, I couldn't find a built-in way to do this, so I built a function. The function calculates a random position, then checks to see if there are any sprites nearby. It repeatedly recalculates a position and checks the sprites until no overlapping sprites are found. Here's a screenshot of my event sheet:

    <img src="http://dl.dropbox.com/u/18659416/fill%20events.jpg">

    Unfortunately, it looks like picking isn't working in my favor, as my logging is showing that no sprites are being looked at in my while loop. Since the function is called from inside another loop that is creating the sprites, I'm guessing that the sprites are never getting added to the selection list.

    Here's my cap file: http://dl.dropbox.com/u/18659416/fill.cap. It includes extra expressions for logging that I removed from the event sheet screenshot for simplicity.

    Here's a screenshot of the current output:

    <img src="http://dl.dropbox.com/u/18659416/overlapping%20sprites.jpg">

    Here's the logging output that the CAP file will add to the clipboard:

    FindEmptyPosition called
    Starting loop, setting position to 209, 432
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 51, 441
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 386, 471
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 331, 271
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 417, 203
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 47, 236
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 623, 230
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 82, 43
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 380, 209
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 541, 223
    Exiting function
    FindEmptyPosition called
    Starting loop, setting position to 239, 388
    Exiting function
    [/code:1v6kg4hs]
    
    Any thoughts on how to fix this?  Or, better yet, a completely different approach that is less complicated?
  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Using this method, you could use overlapping at offset if you want them farther apart than 1 pixel.

    <img src="http://dl.dropbox.com/u/666516/screencapture1330118714.png">

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)