Click on tilemap and return data about the tile

0 favourites
  • 3 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hi,

    I am back. I have searched through 5 pages of tilemap forum posts and either I am not understanding it or it's not being addressed simply.

    My objective:

    At runtime, user mouse clicks on tilemap object, return the tile # in a textbox so the user knows what it is.

    Kind of like if I click on a sprite, I can get the frame #. Let's say user clicks on a tilemap object but more specifically, the tile and there's a number associated, from there I could then have an array with elements that matches with the tile number and then tell the user that they clicked on the "Swamp" tile.

    Is there a simple way to do that?

    I know how to set a tile at X = 5, Y = 5, tile = 5 which will put in the 5th tile in the tilemap tool in the 5th column on the 5th row in my tilemap placed on the layout. But how do I get that same kind of data by using a mouse click. "You clicked on the tile in X = 5, Y = 5, and is the 5th tile in the tilemap tool"

    Thanks. I appreciate how helpful everyone has been over the last few weeks as I continue to improve my skills.

    I am thinking maybe the only way to do this is create the actual tiles at runtime, storing an array after each tile by running a for loop I <= #tiles to generate on each row, nested with a for loop for columns, and then storing what I want to store into other arrays or a single multidimensional one. But then again, how do I return the value of the tile that was clicked on.

  • The expression tilemap.tileat(tilemap.positiontotilex(mouse.x),tilemap.positiontotiley(mouse.y)) will return the tile number at the mouse position.

    This information can be found in the manual.

    construct.net/en/make-games/manuals/construct-3/plugin-reference/tilemap

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks. I bow to you.

    I didn't try the nested technique. I tried them separately and thought I kept getting close. Now I know the magic. Lesson learned.

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