Can I calculate the distance between one tile and another of a different color(in the same Tilemap)?

0 favourites
  • 6 posts
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • So I already made something similar but with sprites but couldn't figure out how to do it with tiles.

    In the image below when the button is active, the player can only paint the "tiles" that are directly adjacent to the blue "tiles".

    Is it possible to do the same with only a tilemap or will I also need other objects like an array?

    Thank you,

    Tagged:

  • Use distance() expression, with either tilemap indices or layout coordinates.

    For example, to check if tiles A and B are adjacent, you can use this condition:

    distance(Ax, Ay, Bx, By)<1.5

    Where Ax,Ay,Bx,By are their indices on the tilemap.

    Or, for example, to check if mouse cursor is on an adjucent tile to tile A:

    distance(Tilemap.TileToPositionX(Ax), Tilemap.TileToPositionY(Ay), Mouse.X, Mouse.y)<(32*1.5)

    32 is tile size in pixels.

    .

    To scan a block of 3x3 tiles around mouse cursor for a particular tile ID:

  • But I can't compare the position of the tiles since it could be any tiles, no specific values.

    So I can't replace "A" and "B" with numbers in:

    distance(Tilemap.TileToPositionX(Ax), Tilemap.TileToPositionY(Ay), Mouse.X, Mouse.y)<(32*1.5).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So which tiles are you interested in comparing exactly, in what situation? You need to define that.

    Otherwise just loop all available options and sort by relevance after.

    If the goal is to determine if the target is adjacent to an existing tile of the correct color, you don't need distance in the first place. Just check adjacent tiles if they meet the criteria.

  • How do I check adjacent tiles when one is clicked? Can I do mouse(x,y)+10 (and after) -10 and after convert it into tile position?

    But I dont need all the adjacent to be of the right tiles

  • + Mouse: On Left button Clicked on Tilemap
    
    ----+ Tilemap: Tile (Tilemap.PositionToTileX(Mouse.X)+1, Tilemap.PositionToTileY(Mouse.Y)) = 1
    ----+ OR Tilemap: Tile (Tilemap.PositionToTileX(Mouse.X)-1, Tilemap.PositionToTileY(Mouse.Y)) = 1
    ----+ OR Tilemap: Tile (Tilemap.PositionToTileX(Mouse.X), Tilemap.PositionToTileY(Mouse.Y)+1) = 1
    ----+ OR Tilemap: Tile (Tilemap.PositionToTileX(Mouse.X), Tilemap.PositionToTileY(Mouse.Y)-1) = 1
    
    -----> Tilemap: Set tile (Tilemap.PositionToTileX(Mouse.X), Tilemap.PositionToTileY(Mouse.Y)) to tile 1 (normal)
    

    On clicked tilemap

    If any of the tiles around the clicked tile is 1

    Set clicked tile to 1

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