Filling a space with non-overlapping sprites

For questions about using Classic.

Post » Fri May 06, 2011 1:19 am

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:



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: [url:1v6kg4hs]http://dl.dropbox.com/u/18659416/fill.cap[/url:1v6kg4hs]. It includes extra expressions for logging that I removed from the event sheet screenshot for simplicity.

Here's a screenshot of the current output:



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

[code:1v6kg4hs]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?
B
2
G
3
Posts: 20
Reputation: 890

Post » Fri May 06, 2011 5:31 am

Using this method, you could use overlapping at offset if you want them farther apart than 1 pixel.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 9 guests