Tiles checking their Neighbours

1 favourites
  • 12 posts
From the Asset Store
Piano tiles
$9.99 USD
Template for a piano tiles game, fully documented in comments and video
  • 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! :)

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • Well, thanks for the help InvaderX but for me personally, this isn't quite what I'm looking for.

  • 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.

  • 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.

  • 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

    +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

    (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 top

  • 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 FILE

  • 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.

  • 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.

  • The overlapping condition only compares against the picked objects and it also does picking. So the second overlapping condition only compares against the objects that were already picked by the first overlapping condition. You can fix it by putting a "pick all" condition between the conditions, or doing it a different way.

    Here is a different way:

    http://dl.dropbox.com/u/5426011/examples14/bitwise_tiles.capx

  • R0J0 you're amazing. Thank you everyone for your help!

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