Tiles checking their Neighbours

Get help using Construct 2

Post » Mon Aug 20, 2012 9:24 pm

Hey there, I've been trying to piece together a way for tiles to check what's around them. But, I can't quite seem to get it. Collision at Offset doesn't work, not properly at least. I was considering Yann's Bitwise plugin, but would anyone know a way without using that? (Mostly curious if it's possible, it must be.)

Basically what I would like to happen, is There be say, Nine blocks. Every block checks if they have a block Above, Below, Left and Right of them. Then, depending on that they turn into a different block. Like Block 0,0 Sees he has a neighbour below and to the right of him, so he turns into a [ corner block. Where as Block 1,0 sees he has a block to the left, right, and below. Thus he's like a -- flat block. And so on, of course.

Any help would be greatly appreciated! :)
B
16
S
3
G
2
Posts: 57
Reputation: 2,078

Post » Mon Aug 20, 2012 10:57 pm

Weird, I'm working on the same thing (just started) and I'm having trouble with collision at offset too. I can get it to work but only if I put a 1 pixel space between the blocks, as soon as they touch it all goes belly up.

Here's the cap I'm testing with to show you better. Ignore the two blocks to the left and right, like I say, it's a test capx. The main bit are the sprites (can't use collision with tiles :( ) the number is generated depending on what blocks surround the black one in the middle. One above add 1, to the right add 2, beneath add 4 and to the left add 8.

If you move the blocks so they're flush against each other the number isn't calculated correctly. Anyone got any idea what I'm doing wrong?

Cheers.

CapX file
B
19
S
5
G
4
Posts: 208
Reputation: 3,960

Post » Tue Aug 21, 2012 3:21 am

Hmm
I would think you would use the compare X event.
Block 1.X > Block 2.X, Destroy Block 1 and 2. Create Object Block 3 at 0.x ,0 .y? Replace zero with position.
B
29
S
7
G
3
Posts: 361
Reputation: 6,187

Post » Tue Aug 21, 2012 7:10 am

Well, thanks for the help InvaderX but for me personally, this isn't quite what I'm looking for.
B
16
S
3
G
2
Posts: 57
Reputation: 2,078

Post » Tue Aug 21, 2012 11:23 am

I managed to sort my issue by just making the collision mask of the blocks a small square in the middle of the sprite and checking for a collision 32 pixels away rather than 16.

Thanks.
B
19
S
5
G
4
Posts: 208
Reputation: 3,960

Post » Tue Aug 21, 2012 1:41 pm

Hehe, kind of funny, had a buddy come up with that solution for me as well, Still curious if there is a way without doing that though.
B
16
S
3
G
2
Posts: 57
Reputation: 2,078

Post » Tue Aug 21, 2012 3:55 pm

Yeah two collision polygon side to side will register as overlapped.
As educated guess, I'd say that it comes from how overlapping is calculated. and basically when two collision polygon are excactly side to side they share the same segment so in a sens they touchs each other.
If you're curious about how it is mathematically calculated, you can have a sneak peek at the source in the exporter folder in common_prelude.js around line 810.
Anyway, if your tiles are precisely aligned on a grid you can do something way simpler by checking position instead of collision polygon

[code]+foreach tile
Local number x=0
Local number y=O
Local number surrounding = 0
+system: every ticks
    -> set x to tile.x
    -> set y to tile.y
+system: pick all tile
+repeat 4 times
+tile: X = x+round(cos(loopindex*90))*cellsize
+tile: Y = y+round(sin(loopindex*90))*cellsize
    -> add (loopindex+1)^2 to surrounding
+system: every ticks
    -> tile: set frame to surrounding[/code]

(untested, I just wrote it there but that's the idea)

then
+1 is when there's a tile on the right
+2 is when there's a tile on the bottom
+4 is when there's a tile on the left
+8 is when there's a tile on the topYann2012-08-21 16:12:54
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Aug 21, 2012 5:55 pm

Can anyone have a look at the new CapX for me? I've no idea why it won't register the collision! I know it's a mess, again it's a test program while I figure things out but I want it to check if the red sprite has collided with the black tile, and then check if there is a neighbour.

If I remove one of the conditions from the event it will register, as soon as I have both, it does nothing. Any idea?

NEW CAP FILEvandinz2012-08-21 17:56:23
B
19
S
5
G
4
Posts: 208
Reputation: 3,960

Post » Tue Aug 21, 2012 6:03 pm

That's exactly what the autotile behavior does.
I've used it in some of my project - it works great, and it's hassle free!
No support for it in the arcade though.
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Tue Aug 21, 2012 8:52 pm

Thanks for that Fimbul, looks like its exactly what I'm trying to achieve. However I always like to learn from my mistakes so if anyone can still point out what I did wrong in that caps I'd really appreciate it. Still learning how construct works with regards to running order of events and conditions.

Cheers.
B
19
S
5
G
4
Posts: 208
Reputation: 3,960

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests