How do I scan a tilemap and detect border tiles?

0 favourites
  • 5 posts
From the Asset Store
Piano tiles
$9.99 USD
Template for a piano tiles game, fully documented in comments and video
  • I'm aware that its possible to check every single tile in a tilemap via a loop and then compare it to its surroundings, but at a larger scale this gives quite a performance hit. Is there a better way to go about this?

    Also is it possible to determine the number of tiles in a tilemap as well?

    Games like territorial.io are able to keep an accurate size of hundreds of players's territory and have borders on a by-tile basis on maps with hundreds of thousands of tiles that can be occupied. Maybe there's some super efficient method I just don't know about?

    Any help is appreciated :)

    Tagged:

  • Looping over all the tiles should only be needed to be done once to get the count and update the edges.

    After that you can easily update the count as you add/remove tiles. You can also update the edges by only looking at the tiles around the tiles that changed.

    If a high amount of tiles change then you may not want to update the edges around each one. Instead you could just update the edges of all the tiles on screen.

    Outside of events, if you can do the update via JavaScript it would be way quicker with the loop. The trick is finding a way to accomplish it

  • R0J0hound

    The size shouldn't really be an issue, but updating the tileset each time the tiles changed seemed tedious, so I tried looking for a border effect of some kind.

    I ended up trying to use your outline effect instead!

    The effect is really nice, I've made it so the outline size would be consistent with the zooming of the map.

    However, the effect isn't pixel perfect.

    I have no experience with effects but tried to have a crack at editing it and managed to get this.

    However, when zoomed in or out a certain amount It will occasionally get a single tiny pixel off, and given I have no experience with effects I don't know what the cause is or what to change.

    As the original creator of the effect, might you know what to do? Thanks for all your help so far and for creating the effect in the first place :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The effect does the outline by shifting copies of the image in four directions. So the corners would look off.

    I may have remembered wrong. It may be 8 directions and the diagonals had sqrt(2) multiplied by it.

    Anyways, I haven’t touched in a long time. Not sure how to get more perfect results.

  • All good, I had to remove the directions to be just 4 instead of 8 and then remove the smoothing effect in between them.

    For anyone wanting to do this it's actually super easy, just remove a0 through a3, rename a4 through a7 to a0 through a3, and edit the ina variable accordingly.

    The imperfect screenshots were from edits involving all a0 through a7 still in use with an edited diag value. Turns out just removing the values used as intermediaries works way better.

    Many thanks for your effect and work in the construct 2 community R0j0hound! You don't know how many devs you've helped.

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