How do I check each tiles of a tilemap

0 favourites
  • 4 posts
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • Hello I would like to know how I can do to check each tile of a tilemap to create a sprite ex tile = 22

  • First this about that concept 'index'. An index is the place that 'something' has in a list of 'things'. An index is always zero based. (the first 'something' has place zero in the list)

    A tile in a tilemap contains the following info :

    Its state (mirrored , flipped ....)

    The index of its graphic contents. (iD)

    The index of its position on a horizontal row (iX)

    The index of its position on a vertical row (iX)

    Besides that, Tilemap knows the position for the center of that tile (X and Y in pixels)

    Using the Conditions, Actions and Expression for Tilemap can be confusing.

    When using the condition 'Compare tile at' (by example) it is asking to input 'Tile X' and 'Tile Y'.

    As a beginner you would expect to fill in positions (In pixels)

    But when you look at the description then you see that is expecting indexes (iX and iY)

    To walk trough a tilemap we need to set up a nested loop.

    First for the horizontal row of tiles.

    The first tile on a row has index zero.

    The last tile on a row has index round(tilemap.Width / size of 1 tile)

    Then a sub condition for the vertical columns.

    The first tile on a column has index zero.

    The last tile on a row has index round(tilemap.Height/ size of 1 tile)

    Looks like this

    Root Event > System > For > Name = "iX" ... start = zero ... end = round(tilemap.Width / size of 1 tile)

    Sub event > System > For > Name = "iY" ... start = zero ... end = round(tilemap.Height/ size of 1 tile)

    That is the nested loop. The index of the loop we access with the expression loopindex("name")

    So we continue with another sub event.

    Tilemap > Compare tile at > Tile X= Loopindex("iX") ... Tile Y = Loopindex("iY") ... Tile = iD

    But often you need the iX and iY for a tile that is nearest to (lets say) Player.X and Player.Y.

    In that case we have to translate X & Y (positions) to iX & iY (indexes)

    Tilemap can translate those (positions to indexes) with the expressions Tilemap.PositionToTileX & Tilemap.PositionToTileY

    So, to compare a tile near the player :

    Tilemap > Compare tile at > Tile X = Tilemap.PositionToTileX(player.X) ... Tile Y = Tilemap.PositionToTileY(player.Y)

    I think met this info, you have the base to understand the manual about Tilemap, and figure out the rest yourself.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Merci pour tout ...

    It works but I just realized that its too much resource for the big maps I have to look for that it only acts on a fixed distance between the set and the player

  • That is what the LOS does already. (had that covered)

    There is no distance calculation faster and less resource demanding than the LOS.

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