How do I Fix layout with random sized boxes filling all gaps

Get help using Construct 2

Post » Mon Apr 17, 2017 10:56 pm

I'm attempting to fill a layout with random sized 9-patches. filling all the gaps.

I've got the width working for 1 row, but want to continue this randomization to fill the whole layout.

the minimum width of a box is 128 and the max can be the layout width (divisible by 128)

same would go with the height.

I'm just not sure how to make it so that they dont generate over each other for the next row.

here's a picture of what i have so far.

Image
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Tue Apr 18, 2017 12:48 am

Made some progress. I've got the boxes all filled up, but some of them are overlapping with themselves in height.

https://dl.dropboxusercontent.com/u/403350/blockGeneration.capx

Any ideas how to fix the ones that are overlapping ?

The approach i went with, was to fill the layout with boxes, then for each box, spawn a 9 patch on top of it, while deleting any boxes that that new 9 path overlapped, until there's no more original boxes.
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Tue Apr 18, 2017 2:09 pm

Ok i figured out a way to get them to stop overlapping now.

For some reason now i get a lot of 1 sized height blocks and increasing my randomization of the starting size to a higher number doesnt seem to work.

https://dl.dropboxusercontent.com/u/403350/generationTest2_v003.capx

I'm sure there's a fancier math solution to all of this lol.

Image
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Wed Apr 19, 2017 9:32 am

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Apr 19, 2017 2:44 pm

@99Instances2Go - Thanks! I'll dig into this and see if i understand what you are doing. I appreciate the time you took to make it !
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938

Post » Wed Apr 19, 2017 4:38 pm

Hi @justifun - I know you've got a solution from @99instances2Go , but this problem stuck in my brain and I couldn't let it go, so here's one I came up with:

https://www.dropbox.com/s/viwoutpz4by0g ... .capx?dl=0

I haven't been able to view @99instances2Go 's as it's done in a later version of C2 - so apologies if it's the same.
B
20
S
8
G
3
Posts: 457
Reputation: 4,053

Post » Wed Apr 19, 2017 4:56 pm

@mekonbekon
@99Instances2Go

I love a good challenge, and i was trying different solutions for a few days before asking the community for help.

Thanks for taking the time to respond.

I also came up with a method. although yours are both more elegant.

I used a tilemap and generated a random area to fill. Then I placed a tiled background over the same area.

Next I checked for the next blank space, and generated another square to fill (making sure to not overlap a previous square.

Its kinda sloppy but it works! check it out!

I'll probably go back and try to optimize it more along the way you guys approached it.

https://dl.dropboxusercontent.com/u/403350/grid_forum.capx


@mekonbekon
@99Instances2Go

added a live demo
Live Demo: (hit refresh to generate a new layout) - https://dl.dropboxusercontent.com/u/403350/grid-forum/index.html
B
87
S
44
G
16
Posts: 1,005
Reputation: 17,938


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 29 guests