In something enclosed, or is it just me?

Get help using Construct 2

Post » Wed Jun 27, 2012 2:55 am

Hi All,

Long time listener, first time requester...

Does anyone know how to determine if an object in an 2D array is enclosed, and if so, by how much 'area'?

In the example below the 'O' is enclosed by 'X's and it's 'area' would be 3...

..xxx..
..x.x..
.x.0x..
.xxxx..

In the example below the 'O' is NOT enclosed


..xxx..
..x....
.x.0x..
.xxxx..

I imagine this involves recursion :( ... but it's been a while...

Any tips/tricks/suggestions?

Thanks all!

Remy-Jay
B
56
S
13
G
1
Posts: 151
Reputation: 4,499

Post » Tue Jul 03, 2012 12:26 am

B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Fri Jul 06, 2012 5:04 am

Thanks R0J0hound -- great example!

Would it be possible to only select groups of sprites in the array that are contiguous in up/down/left/right directions, instead of counting diagonal neighbouring sprites when selecting? Essentially, checking in 4 directions instead of 8...

Clicking on an X below would selects all the X's and the O's wouldn't be selected because a diagonal path needs to be followed to connect them. If one clicked the far right O, it would only be THAT O selected as it doesn't neighbour any sprites in the up.down.left,right directions... etc..

Example Array:

....OOOO...
.XXX..O.O..
.X.X..OO...
.XXX.......
...........

Thanks again..

Remy-Jay
B
56
S
13
G
1
Posts: 151
Reputation: 4,499

Post » Fri Jul 06, 2012 5:11 am

BAh, that array didn't quite render how I intended, however, if you copy it and paste it into a new message body, it seems rectifies itself :)

Remy-Jay
B
56
S
13
G
1
Posts: 151
Reputation: 4,499

Post » Tue Jul 17, 2012 4:53 am

Hmm, I could probably make this easier to understand.. :)

Enclosed Completely:

XXX
XX
XXX

Enclosed 'Diagonally Only'
X
XX
X

Looking for a way to determine enclosed completely only -- current algorithm suggested uses closed 'diagonally AND completely'

Thanks all.

-Remy-Jay
B
56
S
13
G
1
Posts: 151
Reputation: 4,499

Post » Tue Jul 17, 2012 6:16 am

Here is the previous example with only 4-direction select:
http://dl.dropbox.com/u/5426011/examples12/pick_chain_4way.capx

EDIT:
Here's another way using the Array object:
http://dl.dropbox.com/u/5426011/examples12/area_size.capxR0J0hound2012-07-17 06:36:17
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Wed Jul 18, 2012 5:03 am

Wild! Thanks R0JOhound -- the array example is noteworthy too!

B
56
S
13
G
1
Posts: 151
Reputation: 4,499


Return to How do I....?

Who is online

Users browsing this forum: adi pratama and 26 guests